本文整理汇总了C#中eStationCore.Model.StationContext.SaveChangesAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StationContext.SaveChangesAsync方法的具体用法?C# StationContext.SaveChangesAsync怎么用?C# StationContext.SaveChangesAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eStationCore.Model.StationContext
的用法示例。
在下文中一共展示了StationContext.SaveChangesAsync方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Put
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;
}
}
示例2: Post
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;
}
}
示例3: Delete
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;
}
}
示例4: AddStaff
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;
}
}
示例5: Post
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;
}
}
示例6: Post
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;
}
}
示例7: ChangePrice
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;
}
}
示例8: DeletePrelevement
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;
}
}
示例9: Post
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;
}
}