コード例 #1
0
 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();
     }
 }
コード例 #2
0
 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();
     }
 }
コード例 #3
0
        public void Bill_Update(Bill item)
        {
            using (eRestaurantContext context = new eRestaurantContext())
            {
                context.Entry <Bill>(context.Bill.Attach
                                         (item)).State = System.Data.Entity.EntityState.Modified;

                context.SaveChanges();
            }
        }
コード例 #4
0
        public void Reservations_Update(Reservations item)
        {
            using (eRestaurantContext context = new eRestaurantContext())
            {
                context.Entry <Reservations>(context.Reservations.Attach
                                                 (item)).State = System.Data.Entity.EntityState.Modified;

                context.SaveChanges();
            }
        }
コード例 #5
0
        public void Waiters_Update(Waiter item)
        {
            using (eRestaurantContext context = new eRestaurantContext())
            {
                //indicate the updating instance, alter the modified status flag for this instance
                context.Entry <Waiter>(context.Waiters.Attach(item)).State = System.Data.Entity.EntityState.Modified;

                //command not executed until saved
                context.SaveChanges();
            }
        }
コード例 #6
0
 public void SpecialEvents_Update(SpecialEvent item)
 {
     using (eRestaurantContext context = new eRestaurantContext())
     {
         //indicate the updating item instance
         //alter the Modified Status flag for this instanc
         context.Entry <SpecialEvent>(context.SpecialEvents.Attach(item)).State =
             System.Data.Entity.EntityState.Modified;
         //command is not executed until it is actually saved.
         context.SaveChanges();
     }
 }
コード例 #7
0
        public void waiter_Update(Waiter item)
        {
            using (eRestaurantContext context = new eRestaurantContext())
            {
                //indicate the updating item instance
                //alter the Modified status flag for this instance

                context.Entry <Waiter>(context.Waiters.Attach(item)).State =
                    System.Data.Entity.EntityState.Modified; //telling it update, SpecialEvent is the entity;
                //attach is passing in the the item

                context.SaveChanges();
            }
        }
コード例 #8
0
        public void Waiter_Update(Waiter item)
        {
            //set context
            using (eRestaurantContext context = new eRestaurantContext())
            {
                // indicate the updating item instance
                //alter the modified status flag for the particular instance

                context.Entry <Waiter>(context.Waiters.Attach(item)).State =
                    System.Data.Entity.EntityState.Modified;
                //command is not executed until it is actually saved.
                context.SaveChanges();
            }
        }
コード例 #9
0
        //seating of reservations
        public void SeatCustomer(DateTime when, int reservationId, List <byte> tables, int waiterId)
        {
            var availableSeats = SeatingByDateTime(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 reservation", 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 table to 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);
        }