public async Task<bool> Put(Fuel myFuel) { using (var db = new StationContext()) { myFuel.LastEditDate = DateTime.Now; db.Fuels.Attach(myFuel); db.Entry(myFuel).State = EntityState.Modified; return await db.SaveChangesAsync() > 0; } }
public async Task<bool> Post(Citerne myCiternes) { using (var db = new StationContext()) { if (myCiternes.CiterneGuid == Guid.Empty) myCiternes.CiterneGuid = Guid.NewGuid(); myCiternes.DateAdded = DateTime.Now; myCiternes.LastEditDate = DateTime.Now; db.Citernes.Add(myCiternes); return await db.SaveChangesAsync() > 0; } }
public async Task<bool> Delete(Guid fuelGuid) { using (var db = new StationContext()) { var myObject = await db.Fuels.FindAsync(fuelGuid); if (myObject == null) throw new InvalidOperationException("FUEL_NOT_FOUND"); myObject.LastEditDate = DateTime.Now; myObject.IsDeleted = true; db.Fuels.Attach(myObject); db.Entry(myObject).State = EntityState.Modified; return await db.SaveChangesAsync() > 0; } }
public async Task<bool> AddStaff(Staff myStaff) { using (var db = new StationContext()) { if (myStaff.StaffGuid == Guid.Empty) myStaff.StaffGuid = Guid.NewGuid(); if (myStaff.Person.PersonGuid == Guid.Empty) myStaff.Person.PersonGuid = Guid.NewGuid(); await myStaff.Person.Validate(); db.Set<Person>().Add(myStaff.Person); db.Staffs.Add(myStaff); return await db.SaveChangesAsync() > 0; } }
public async Task<bool> Post(Fuel myFuel) { using (var db = new StationContext()) { if (myFuel.FuelGuid == Guid.Empty) myFuel.FuelGuid = Guid.NewGuid(); myFuel.DateAdded = DateTime.Now; myFuel.LastEditDate = DateTime.Now; db.Fuels.Add(myFuel); if (!myFuel.Prices.Any()) return db.SaveChanges() > 0; if (myFuel.Prices.First().PriceGuid == Guid.Empty) myFuel.Prices.First().PriceGuid = Guid.NewGuid(); myFuel.Prices.First().ProductGuid = myFuel.FuelGuid; myFuel.Prices.First().FromDate = DateTime.Now; db.Set<Price>().Add(myFuel.Prices.First()); return await db.SaveChangesAsync() > 0; } }
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> ChangePrice(Guid oilGuid, double newPrice) { using (var db = new StationContext()) { var myOil = db.Oils.Find(oilGuid); myOil.CurrentUnitPrice = newPrice; myOil.LastPriceUpdate = DateTime.Now; myOil.LastEditDate = DateTime.Now; db.Oils.Attach(myOil); db.Entry(myOil).State = EntityState.Modified; return await db.SaveChangesAsync() > 0; } }
public async Task<bool> DeletePrelevement(Guid oilPrelevementGuid) { using (var db = new StationContext()) { var myObject = await db.OilPrelevements.FindAsync(oilPrelevementGuid); if (myObject == null) throw new InvalidOperationException("PRELEVEMENT_NOT_FOUND"); myObject.LastEditDate = DateTime.Now; myObject.DeleteDate = DateTime.Now; myObject.IsDeleted = true; db.OilPrelevements.Attach(myObject); db.Entry(myObject).State = EntityState.Modified; return await db.SaveChangesAsync() > 0; } }
public async Task<bool> Post(List<OilPrelevement> oilPrelevements, DateTime fromDate) { using (var db = new StationContext()) { foreach (var prelevement in oilPrelevements) { if (prelevement.OilPrelevementGuid == Guid.Empty) prelevement.OilPrelevementGuid = Guid.NewGuid(); prelevement.CurrentPrice = db.Oils.Find(prelevement.OilGuid).CurrentUnitPrice; var lastOne = StaticGetLastPrelevement(prelevement.OilGuid); prelevement.Result = - prelevement.Meter + lastOne.Meter + GetDeliveries(prelevement.OilGuid, lastOne.DatePrelevement.GetValueOrDefault(), fromDate); if (prelevement.Result < 0) throw new CoolException( $"{db.Oils.Find(prelevement.OilGuid).Libel} : Le stock restant ne doit pas etre Supérieur a " + lastOne.Meter + GetDeliveries(prelevement.OilGuid, lastOne.DatePrelevement.GetValueOrDefault(), fromDate)); if (prelevement.Result > StaticGetOilBalance(prelevement.OilGuid)) throw new CoolException( $"{db.Oils.Find(prelevement.OilGuid).Libel}: Le stock restant ne doit pas etre Supérieur a " + StaticGetOilBalance(prelevement.OilGuid)); prelevement.DatePrelevement = fromDate; prelevement.DateAdded = DateTime.Now; prelevement.LastEditDate = DateTime.Now; db.OilPrelevements.Add(prelevement); } return await db.SaveChangesAsync() > 0; } }
public async Task<bool> Post(Price newPrice) { using (var db = new StationContext()) { if (!db.Fuels.Any(f => f.FuelGuid == newPrice.ProductGuid)) throw new InvalidOperationException("FUEL_REFERENCE_NOT_FOUND"); if (newPrice.PriceGuid == Guid.Empty) newPrice.PriceGuid = Guid.NewGuid(); newPrice.DateAdded = DateTime.Now; newPrice.LastEditDate = DateTime.Now; db.Set<Price>().Add(newPrice); return await db.SaveChangesAsync() > 0; } }
public async Task<bool> Post(FuelDelivery fuelDelivery) { using (var db = new StationContext()) { if (fuelDelivery.FuelDeliveryGuid == Guid.Empty) fuelDelivery.FuelDeliveryGuid = Guid.NewGuid(); fuelDelivery.DateAdded = DateTime.Now; fuelDelivery.LastEditDate = DateTime.Now; db.FuelDeliverys.Add(fuelDelivery); return await db.SaveChangesAsync() > 0; } }