internal Models.Prices ToPrices() { var prices = new Models.Prices(); var hasE5 = decimal.TryParse(E5, out var e5Res); prices.E5 = hasE5 ? FSharpOption <decimal> .Some(e5Res) : FSharpOption <decimal> .None; var hasE10 = decimal.TryParse(E10, out var e10Res); prices.E10 = hasE10 ? FSharpOption <decimal> .Some(e10Res) : FSharpOption <decimal> .None; var hasDiesel = decimal.TryParse(Diesel, out var dieselRes); prices.Diesel = hasDiesel ? FSharpOption <decimal> .Some(dieselRes) : FSharpOption <decimal> .None; return(prices); }
public IHttpActionResult PostPrices(int id) { var priceInDb = _context.Prices.SingleOrDefault(t => t.PriceId == id); if (priceInDb != null) { priceInDb.Amount = float.Parse(HttpContext.Current.Request.Params["Amount"], CultureInfo.InvariantCulture.NumberFormat); priceInDb.PriceDescription = HttpContext.Current.Request.Params["PriceDescription"]; } else { var prices = new Models.Prices(); prices.Amount = float.Parse(HttpContext.Current.Request.Params["Amount"], CultureInfo.InvariantCulture.NumberFormat); prices.PriceDescription = HttpContext.Current.Request.Params["PriceDescription"]; _context.Prices.Add(prices); } _context.SaveChanges(); return(Ok()); }
public static Result <PriceRequestError, Models.Prices> ReadAsPrice(this JsonReader reader) { reader.Read(); if (reader.TokenType != JsonToken.StartObject) { return(null); } var prices = new Models.Prices(); reader.Read(); while (reader.TokenType != JsonToken.EndObject) { switch (reader.Value) { case "status": { var status = reader.ReadAsString(); switch (status) { case "no prices": return(Result <PriceRequestError, Models.Prices> .Error(PriceRequestError.NoPrices)); case "closed": return(Result <PriceRequestError, Models.Prices> .Error(PriceRequestError.Closed)); } break; } case "e5": { var price = reader.ReadAsDecimal(); prices.E5 = price.HasValue ? FSharpOption <decimal> .Some(price.Value) : FSharpOption <decimal> .None; break; } case "e10": { var price = reader.ReadAsDecimal(); prices.E10 = price.HasValue ? FSharpOption <decimal> .Some(price.Value) : FSharpOption <decimal> .None; break; } case "diesel": { var price = reader.ReadAsDecimal(); prices.Diesel = price.HasValue ? FSharpOption <decimal> .Some(price.Value) : FSharpOption <decimal> .None; break; } } reader.Read(); } return(Result <PriceRequestError, Models.Prices> .Ok(prices)); }