當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。