예제 #1
0
 public void SeatCustomer(DateTime when, int reservationId, List<byte> tables, int waiterId)
 {
     var availableSeats = AvailableSeatingByDateTime(when.Date, when.TimeOfDay);
     using (eRestaurantContext 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.");
         }
         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 customer", 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 and change the reservation's status to arrived
         foreach (var tableNumber in tables)
         {
             reservation.Tables.Add(context.Tables.Single(x => x.TableNumber == tableNumber));
         }
         reservation.ReservationStatus = Reservation.Arrived;
         var updatable = context.Entry(context.Reservations.Attach(reservation));
         updatable.Property(x => x.ReservationStatus).IsModified = true;
         //updatable.Reference(x=>x.Tables).
         // 3) 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);
 }
예제 #2
0
 /// <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
     }
 }
예제 #3
0
 public void Bill_Delete(Bill item)
 {
     using (eRestaurantContext context = new eRestaurantContext())
     {
         Bill existing = context.Bill.Find(item.BillID);
         context.Bill.Remove(existing);
         context.SaveChanges();
     }
 }
예제 #4
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();
            }
        }
예제 #5
0
 public void Bill_Add(Bill item)
 {
     using (eRestaurantContext context = new eRestaurantContext())
     {
         Bill added = null;
         added = context.Bill.Add(item);
         context.SaveChanges();                                                  //Commits the add to the database.
                                                                                 //Furthermore, this evaluates the annotations (validates) on the entity.
                                                                                 //Included: [Required], [StringLength], [Range], etc.
     }
 }
예제 #6
0
        // the command from the code behind is NOT using an ODS
        // therefore it does NOT need [DataObjectMethod]
        public void SeatCustomer(DateTime when, byte tablenumber, int numberinparty, int waiterid)
        {
            // business logic checking should be done before any database processing
            // rule 1: table must be available
            // rule 2: table size must be greater than or = to numberinparty

            //get the available seats
            var availableseats = AvailableSeatingByDateTime(when.Date, when.TimeOfDay);

            //start the transaction
            using (eRestaurantContext context = new eRestaurantContext())
            {
                // create a list<> to hold error messages
                List<string> errors = new List<string>();

                if(!availableseats.Exists(foreachseat => foreachseat.Table == tablenumber))
                {
                    // table is not available
                    errors.Add("Table is currently not available");
                }
                if(!availableseats.Exists(foreachseat => foreachseat.Table == tablenumber
                                            && foreachseat.Seating >= numberinparty))
                {
                    errors.Add("Insufficient seating capacity for number of customer");
                }

                // check of validation
                if(errors.Count > 0)
                {
                    //there is a business rule exception
                    throw new BusinessRuleException("Unable to seat customer", errors);
                }

                // we can assume that the data is valid at this point
                // in our system as soon as a customer is seated a Bill is started
                Bill seatcustomer = new Bill();

                seatcustomer.BillDate = when;
                seatcustomer.NumberInParty = numberinparty;
                seatcustomer.WaiterID = waiterid;
                seatcustomer.TableID = tablenumber;
                seatcustomer.PaidStatus = false;

                //make the request to entityframework to add a record to the database
                context.Bills.Add(seatcustomer);

                //commit
                context.SaveChanges();

            } // end of transaction
        }