当前位置: 首页>>代码示例>>C#>>正文


C# StationContext.SaveChangesAsync方法代码示例

本文整理汇总了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;
            }
        }
开发者ID:HalidCisse,项目名称:eStation,代码行数:11,代码来源:FuelManager.cs

示例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;
            }
        }       
开发者ID:HalidCisse,项目名称:eStation,代码行数:13,代码来源:CiternesManager.cs

示例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;
            }
        }
开发者ID:HalidCisse,项目名称:eStation,代码行数:16,代码来源:FuelManager.cs

示例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;
            }
        }
开发者ID:HalidCisse,项目名称:eStation,代码行数:16,代码来源:HrManager.cs

示例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;
            }
        }        
开发者ID:HalidCisse,项目名称:eStation,代码行数:20,代码来源:FuelManager.cs

示例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;
            }
        }
开发者ID:HalidCisse,项目名称:eStation,代码行数:21,代码来源:PompesManager.cs

示例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;
            }
        }
开发者ID:HalidCisse,项目名称:eStation,代码行数:16,代码来源:OilManager.cs

示例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;
            }
        }
开发者ID:HalidCisse,项目名称:eStation,代码行数:17,代码来源:OilManager.cs

示例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;
            }
        }
开发者ID:HalidCisse,项目名称:eStation,代码行数:30,代码来源:OilManager.cs


注:本文中的eStationCore.Model.StationContext.SaveChangesAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。