public async Task <bool> Post(FuelPrelevement myPrelevement) { using (var db = new StationContext()) { if (myPrelevement.PrelevementGuid == Guid.Empty) { myPrelevement.PrelevementGuid = Guid.NewGuid(); } var citerneGuid = db.Pompes.Find(myPrelevement.PompeGuid).CiterneGuid; if (citerneGuid != null) { myPrelevement.CiterneGuid = (Guid)citerneGuid; } else { throw new ArgumentException("CAN_NOT_FIND_CITERNE"); } myPrelevement.CurrentPrice = (await FuelManager.GetFuelCurrentPrice(db.Pompes.Find(myPrelevement.PompeGuid).Citerne.FuelGuid)); myPrelevement.DateAdded = DateTime.Now; myPrelevement.LastEditDate = DateTime.Now; db.Set <FuelPrelevement>().Add(myPrelevement); return(await db.SaveChangesAsync() > 0); } }
public async Task <bool> Post(Purchase myPurchase) { using (var db = new StationContext()) { switch (myPurchase.ProductType) { case ProductType.Fuel: myPurchase.Sum = myPurchase.Quantity * (await FuelManager.GetFuelCurrentPrice(myPurchase.ProductGuid)); myPurchase.Description = $"{myPurchase.Quantity.ToString("0.##\\ L")} {(await db.Fuels.FindAsync(myPurchase.ProductGuid)).Libel}"; break; case ProductType.Oil: myPurchase.Sum = myPurchase.Quantity * (await OilManager.StaticGet(myPurchase.ProductGuid)).CurrentUnitPrice; myPurchase.Description = $"{"Bidon".ToQuantity((int) myPurchase.Quantity)} {(await db.Oils.FindAsync(myPurchase.ProductGuid)).Libel}"; break; } if (myPurchase.PurchaseGuid == Guid.Empty) { myPurchase.PurchaseGuid = Guid.NewGuid(); } if (myPurchase.PurchaseState == PurchaseState.Paid) { myPurchase.PurchaseDate = DateTime.Now; } myPurchase.DateAdded = myPurchase.PurchaseDate; myPurchase.LastEditDate = DateTime.Now; db.Purchases.Add(myPurchase); return(await db.SaveChangesAsync() > 0); } }