當前位置: 首頁>>代碼示例>>C#>>正文


C# eRestaurantContext.SaveChanges方法代碼示例

本文整理匯總了C#中eRestaurantSystem.DAL.eRestaurantContext.SaveChanges方法的典型用法代碼示例。如果您正苦於以下問題:C# eRestaurantContext.SaveChanges方法的具體用法?C# eRestaurantContext.SaveChanges怎麽用?C# eRestaurantContext.SaveChanges使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在eRestaurantSystem.DAL.eRestaurantContext的用法示例。


在下文中一共展示了eRestaurantContext.SaveChanges方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SpecialEvents_Update

 public void SpecialEvents_Update(SpecialEvent item)
 {
     using (eRestaurantContext context = new eRestaurantContext())
     {
         context.Entry<SpecialEvent>(context.SpecialEvents.Attach(item)).State =System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
開發者ID:SeymoreThrottle,項目名稱:DVCSExercise,代碼行數:8,代碼來源:eRestaurantController.cs

示例2: SpecialEvents_Delete

 public void SpecialEvents_Delete(SpecialEvent item)
 {
     using (eRestaurantContext context = new eRestaurantContext())
     {
         SpecialEvent existing = context.SpecialEvents.Find(item.EventCode);
         context.SpecialEvents.Remove(existing);
         context.SaveChanges();
     }
 }
開發者ID:RelSavo,項目名稱:Temp2,代碼行數:9,代碼來源:eRestaurantController.cs

示例3: SpecialEvents_Add

 public void SpecialEvents_Add(SpecialEvent item)
 {
     using(eRestaurantContext context = new eRestaurantContext())
     {
         SpecialEvent added = null;
         added = context.SpecialEvents.Add(item);
         context.SaveChanges();                                                  //Commits the add to the database.
                                                                                 //Furthermore, this evaluates the annotations (validates) on the entity.
                                                                                 //Included: [Required], [StringLength], [Range], etc.
     }
 }
開發者ID:RelSavo,項目名稱:Temp2,代碼行數:11,代碼來源:eRestaurantController.cs

示例4: SpecialEvents_Add

 public void SpecialEvents_Add(SpecialEvent item)
 {
     using (eRestaurantContext context = new eRestaurantContext())
     {
         SpecialEvent added = null;
         added = context.SpecialEvents.Add(item);
         // commits the add to the database
         // evaluates the annotations (validations) on your entity
         // [Required],[StringLength],[Range],...
         context.SaveChanges();  
     }
 }
開發者ID:SeymoreThrottle,項目名稱:DVCSExercise,代碼行數:12,代碼來源:eRestaurantController.cs

示例5: SpecialEvents_Delete

        public void SpecialEvents_Delete(SpecialEvent item)
        {
            using (eRestaurantContext context = new eRestaurantContext())
            {
                //lookup the instance and record if found

                SpecialEvent existing = context.SpecialEvents.Find(item.EventCode);
                //setup command to execute the delete
                context.SpecialEvents.Remove(existing);
                //command is not executed untill it is actually saved
                context.SaveChanges();
            }
        }
開發者ID:DilpreetSandhu,項目名稱:InClassDemos-master,代碼行數:13,代碼來源:AdminController.cs

示例6: Waiters_Update

        public void Waiters_Update(Waiter item)
        {
            using (eRestaurantContext context = new eRestaurantContext())
            {

                // indicate the updateing item instance
                //alter the Modified Status flag for this instance
                context.Entry<Waiter>(context.Waiters.Attach(item)).State =
               System.Data.Entity.EntityState.Modified;
                //command is not executed until it it actually saved.
                context.SaveChanges();
            }
        }
開發者ID:swu18,項目名稱:InClassDemo,代碼行數:13,代碼來源:AdminController.cs

示例7: Waiters_Add

        public int Waiters_Add(Waiter item)
        {
            using (eRestaurantContext context = new eRestaurantContext())
            {

                // these methods are execute using an instance level item
                // set up a instance pointer and initialize to null
                Waiter added = null;
                // set up commanc to execute the add
                added = context.Waiters.Add(item);
                //command is not executed until it it actually saved.
                context.SaveChanges();
               // the Waiter instance added contains the newly inserted
               // record to sql including the generated play value
                return added.WaiterID;

            }
        }
開發者ID:swu18,項目名稱:InClassDemo,代碼行數:18,代碼來源:AdminController.cs

示例8: Waiters_Delete

        public void Waiters_Delete(Waiter item)
        {
            using (eRestaurantContext context = new eRestaurantContext())
             {

                 //lookup the instance and record if found (set pointer to instance)
                 Waiter existing = context.Waiters.Find(item.WaiterID);

                 //setup the command to execute the delete
                 context.Waiters.Remove(existing);
                 //command is not executed until it is actually saved.
                 context.SaveChanges();
             }
        }
開發者ID:swu18,項目名稱:InClassDemo,代碼行數:14,代碼來源:AdminController.cs

示例9: SeatCustomer

        //seating of reservations
        public void SeatCustomer(DateTime when, int reservationId, List<byte> tables, int waiterId)
        {
            var availableSeats = AvailableSeatingByDateTime(when.Date, when.TimeOfDay);
            using (var context = new eRestaurantContext())
            {
                List<string> errors = new List<string>();
                // Rule checking:
                // - Reservation must be in Booked status
                // - Table must be available - typically a direct check on the table, but proxied based on the mocked time here
                // - Table must be big enough for the # of customers
                var reservation = context.Reservations.Find(reservationId);
                if (reservation == null)
                    errors.Add("The specified reservation does not exist");
                else if (reservation.ReservationStatus != Reservation.Booked)
                    errors.Add("The reservation's status is not valid for seating. Only booked reservations can be seated.");

                //is there sufficient seating available for the reservation
                var capacity = 0;
                foreach (var tableNumber in tables)
                {
                    if (!availableSeats.Exists(x => x.Table == tableNumber))
                        errors.Add("Table " + tableNumber + " is currently not available");
                    else
                        capacity += availableSeats.Single(x => x.Table == tableNumber).Seating;
                }
                if (capacity < reservation.NumberInParty)
                    errors.Add("Insufficient seating capacity for number of customers. Alternate tables must be used.");
                if (errors.Count > 0)
                    throw new BusinessRuleException("Unable to seat reseervation", errors);

                // 1) Create a blank bill with assigned waiter
                Bill seatedCustomer = new Bill()
                {
                    BillDate = when,
                    NumberInParty = reservation.NumberInParty,
                    WaiterID = waiterId,
                    ReservationID = reservation.ReservationID
                };
                context.Bills.Add(seatedCustomer);
                // 2) Add the tables for the reservation (ReservationTables) n adds depending on the number of tables assigned
                foreach (var tableNumber in tables)
                    reservation.Tables.Add(context.Tables.Single(x => x.TableNumber == tableNumber));

                // 3) Update the reservation status to arrived
                reservation.ReservationStatus = Reservation.Arrived;
                var updatable = context.Entry(context.Reservations.Attach(reservation));
                updatable.Property(x => x.ReservationStatus).IsModified = true;
                //updatable.Reference(x=>x.Tables).

                // 4) Save changes
                context.SaveChanges();
            }
            //string message = String.Format("Not yet implemented. Need to seat reservation {0} for waiter {1} at tables {2}", reservationId, waiterId, string.Join(", ", tables));
            //throw new NotImplementedException(message);
        }
開發者ID:swu18,項目名稱:InClassDemo,代碼行數:56,代碼來源:AdminController.cs

示例10: Waiters_Update

        public void Waiters_Update(Waiter item)
        {
            using (eRestaurantContext context = new eRestaurantContext())
            {
                context.Entry<Waiter>(context.Waiters.Attach(item)).State = System.Data.Entity.EntityState.Modified;

                context.SaveChanges();

            }
        }
開發者ID:SuperBigL,項目名稱:InClassDemos,代碼行數:10,代碼來源:AdminController.cs

示例11: Waiter_Add

        public int Waiter_Add(Waiter item)
        {
            //input into this method is at the instance level
            using (eRestaurantContext context = new eRestaurantContext())
            {
                //create a pointer variable for the instance type
                //set this pointer to null
                Waiter added = null;

                //set up the add request for the dbContext
                added = context.Waiters.Add(item);

                //Saving the changes will cause the .Add to execute
                //commits the add to the database
                //evaluates the annotations(validation) on your entity
                context.SaveChanges();

                return added.WaiterID;
            }
        }
開發者ID:gthind4,項目名稱:InClassDemo,代碼行數:20,代碼來源:AdminController.cs

示例12: SpecialEvent_Add

 public void SpecialEvent_Add(SpecialEvent item)
 {
     using (eRestaurantContext context = new eRestaurantContext())
     {
         SpecialEvent added = null;
         added = context.SpecialEvents.Add(item);
         //comment is not used until it is actully save
         context.SaveChanges();
     }
 }
開發者ID:xdu3,項目名稱:InClassDemo,代碼行數:10,代碼來源:AdminController.cs

示例13: Waiter_Delete

        public void Waiter_Delete(Waiter item)
        {
            using (eRestaurantContext context = new eRestaurantContext())
            {
                //look th eitem instance on th edatabase to detemine if the insatnce exist
                //on the delete make sure u have PK name
                Waiter existing = context.Waiters.Find(item.WaiterID);

                //set up the data command request
                existing = context.Waiters.Remove(existing);

                //commit the action to happen
                context.SaveChanges();

            }
        }
開發者ID:bartykbayev1,項目名稱:InClassDemos,代碼行數:16,代碼來源:AdminController.cs

示例14: Waiters_Delete

 public void Waiters_Delete(Waiter item)
 {
     using (eRestaurantContext context = new eRestaurantContext())
     {
         //look the item instance on the database to determine if it exists
         //on the delete ensure you reference the P-Key
         Waiter existing = context.Waiters.Find(item);
         //set up the data request command
         context.Waiters.Remove(existing);
         //commit the action to happen
         context.SaveChanges();
     }
 }
開發者ID:SuperBigL,項目名稱:InClassDemos,代碼行數:13,代碼來源:AdminController.cs

示例15: SeatCustomer

 /// <summary>
 /// Seats a customer that is a walk-in
 /// </summary>
 /// <param name="when">A mock value of the date/time (Temporary - see remarks)</param>
 /// <param name="tableNumber">Table number to be seated</param>
 /// <param name="customerCount">Number of customers being seated</param>
 /// <param name="waiterId">Id of waiter that is serving</param>
 public void SeatCustomer(DateTime when, byte tableNumber, int customerCount, int waiterId)
 {
     var availableSeats = AvailableSeatingByDateTime(when.Date, when.TimeOfDay);
     using (var context = new eRestaurantContext())
     {
         List<string> errors = new List<string>();
         // Rule checking:
         // - Table must be available - typically a direct check on the table, but proxied based on the mocked time here
         // - Table must be big enough for the # of customers
         if (!availableSeats.Exists(x => x.Table == tableNumber))
         {
             errors.Add("Table is currently not available");
         }
         else if (!availableSeats.Exists(x => x.Table == tableNumber && x.Seating >= customerCount))
         {
             errors.Add("Insufficient seating capacity for number of customers.");
         }
         if (errors.Count > 0)
         {
             throw new BusinessRuleException("Unable to seat customer", errors);
         }
         Bill seatedCustomer = new Bill()
         {
             BillDate = when,
             NumberInParty = customerCount,
             WaiterID = waiterId,
             TableID = context.Tables.Single(x => x.TableNumber == tableNumber).TableID
         };
         context.Bills.Add(seatedCustomer);
         context.SaveChanges(); //Commit in a transaction
     }
 }
開發者ID:kgibson5,項目名稱:ClassDemos,代碼行數:39,代碼來源:eRestaurantController.cs


注:本文中的eRestaurantSystem.DAL.eRestaurantContext.SaveChanges方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。