コード例 #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 SpecialEvents_Delete(SpecialEvent item)
 {
     using (eRestaurantContext context = new eRestaurantContext())
     {
         SpecialEvent existing = context.SpecialEvents.Find(item.EventCode);
         context.SpecialEvents.Remove(existing);
         context.SaveChanges();
     }
 }
コード例 #3
0
 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.
     }
 }
コード例 #4
0
 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();  
     }
 }
コード例 #5
0
        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();
            }
        }
コード例 #6
0
ファイル: AdminController.cs プロジェクト: swu18/InClassDemo
        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();
            }
        }
コード例 #7
0
ファイル: AdminController.cs プロジェクト: swu18/InClassDemo
        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;

            }
        }
コード例 #8
0
ファイル: AdminController.cs プロジェクト: swu18/InClassDemo
        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();
             }
        }
コード例 #9
0
ファイル: AdminController.cs プロジェクト: swu18/InClassDemo
        //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);
        }
コード例 #10
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();

            }
        }
コード例 #11
0
        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;
            }
        }
コード例 #12
0
 public void SpecialEvents_Delete(SpecialEvent item)
 {
     using (eRestaurantContext context = new eRestaurantContext())
     {
         //look up the item instance on the database to determine if the instance exists
         //On delete make sutre u reference the PK
         SpecialEvent existing = context.SpecialEvents.Find(item.EventCode);
         //set up the delete request command
         context.SpecialEvents.Remove(existing);
         //commit the action to happen
         context.SaveChanges();
     }
 }
コード例 #13
0
ファイル: AdminController.cs プロジェクト: xdu3/InClassDemo
        public int Waiters_Add(Waiter item)
        {
            using (eRestaurantContext context = new eRestaurantContext())
            {
                Waiter added = null;
                added = context.Waiters.Add(item);
                //comment is not used until it is actully save
                context.SaveChanges();

                //the waiter instence added contains the newly inserted
                //record to sql including the genrated pkey value
                return added.WaiterID;
            }
        }
コード例 #14
0
ファイル: AdminController.cs プロジェクト: xdu3/InClassDemo
 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();
     }
 }
コード例 #15
0
        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();

            }
        }
コード例 #16
0
        public int Waiters_Add(Waiter item)
        {
            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();
                //added contains the data of the newly added waiter
                //including rgw pkey value.
                return added.WaiterID;

            }
        }
コード例 #17
0
 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();
     }
 }
コード例 #18
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
     }
 }
コード例 #19
0
ファイル: AdminController.cs プロジェクト: swu18/InClassDemo
        //the ccommand 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: ttable 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(foreahcseat => foreahcseat.Table == tablenumber
                                        && foreahcseat.Seating >= numberinparty))
                {
                    errors.Add("Insufficient seating capacity for number of customers");
                }

                //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
        }
コード例 #20
0
 public void Waiter_Delete(Waiter item)
 {
     using (eRestaurantContext context = new eRestaurantContext())
     {
         Waiter existing = context.Waiters.Find(item.WaiterID);
         context.Waiters.Remove(existing);
         context.SaveChanges();
     }
 }
コード例 #21
0
ファイル: AdminController.cs プロジェクト: swu18/InClassDemo
 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;
          //setup the command to execute the add
          added = context.Waiters.Add(item);
          //command is not executed until it is actually saved.
          context.SaveChanges();
          //added contains the data of the newly added waiter
          //including the pkey value.
          return added.WaiterID;
      }
 }
コード例 #22
0
        public void SpecialEvents_Delete(SpecialEvent item)
        {
            using (eRestaurantContext context = new eRestaurantContext())
            {
                //lookup the instance and record if found (set pointer to instance)

                SpecialEvent existing = context.SpecialEvents.Find(item.EventCode);

                //Setup the comand to execute the delete
                context.SpecialEvents.Remove(existing);
                context.SaveChanges(); 

            }

      
        #endregion
        } //eof class
コード例 #23
0
ファイル: AdminController.cs プロジェクト: swu18/InClassDemo
        public void SeatCustomer(DateTime when, byte tablenumber,
                                 int numberinparty, int waiterid)
        {
            //business logic checking should be done
            //BEFORE attempting to place data on the database
            //rule1: is the seat available
            //rule2: is the selected table capicity sufficicent
            // get the available seats

            var availableseatrs = AvailableSeatingByDateTime(when.Date,
                                                             when.TimeOfDay);
            // start my transaction
            using (eRestaurantContext context = new eRestaurantContext())
            {

                //create a holding list for possible  business logic
                //this is need for the MessageUserControl
                List<string> errors = new List<string>();

                if (!availableseatrs.Exists(foreachseat => foreachseat.Table == tablenumber))
                {

                    // the table numberis not available
                    errors.Add("Table is currently not availabe");

                }
                else if (!availableseatrs.Exists(foreachseat => foreachseat.Table == tablenumber
                         && foreachseat.Seating >= numberinparty))
                {

                    //the table is available but not large enough
                    errors.Add("Insufficient seating capacity for number of customers");

                }
                //check if any errors to business rules exist
                if (errors.Count > 0)
                {
                    //throw an exception which will terminate the transaction
                    //BusinessRuleException is part of the MessageUserControl setup
                    throw new BusinessRuleException("unable to seat customer", errors);
                    //assume your data is valid
                    //create an instance of the Bill entity and fill with data
                    Bill seatedcustomer = new Bill();
                    seatedcustomer.BillDate = when;
                    seatedcustomer.NumberInParty = numberinparty;
                    seatedcustomer.WaiterID = waiterid;
                    seatedcustomer.TableID = tablenumber;

                    //issue the command to add a record to the bill entity
                    context.Bills.Add(seatedcustomer);
                    //save sand commin the changes to the entity
                    context.SaveChanges();
                }

            }
        }
コード例 #24
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();

            }
        }
コード例 #25
0
ファイル: AdminController.cs プロジェクト: swu18/InClassDemo
        public void Waiters_Delete(Waiter item)
        {
            using (eRestaurantContext context = new eRestaurantContext())
            {

                // indicate the updateing item instance
                //alter the Modified Status flag for this instance
                Waiter existing = context.Waiters.Find(item.WaiterID);
                // set up the command to execute the delete
                context.Waiters.Remove(existing);
                //command is not executed until it it actually saved.
                context.SaveChanges();
            }
        }
コード例 #26
0
        public void waiter_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 comand to execute the delete
                context.Waiters.Remove(existing);
                context.SaveChanges(); 

            }
      
       
        
    }//eofclass
コード例 #27
0
        public void SpecialEvents_Add(SpecialEvent item)
        {
            using (eRestaurantContext context = new eRestaurantContext())
            {
             //these methods are execute using an instance level item

            //Set up a instance pointer and intialize to null
            SpecialEvent added = null;
            //setup the command to execute the add
            added = context.SpecialEvents.Add(item);
             //command is not executed untill it is actually saved
            context.SaveChanges();
            }
        }
コード例 #28
0
 public int Waiter_Add(Waiter item)
 {
     using (eRestaurantContext context = new eRestaurantContext())
     {
         //these methods are executed using an instant level item.
         //setup a instance pointer and initialize to null
         Waiter added = null;
         //setup the command to execute the add
         added = context.Waiters.Add(item);
         //command is not executed until it is saved
         context.SaveChanges();
         //the waiter instance added cointains the newly created record to SQL including the generated Primary key value\
         return added.WaiterID;
     }
 }
コード例 #29
0
        public void SpecialEvents_Update(SpecialEvent item)
        {
            using (eRestaurantContext context = new eRestaurantContext())
            {
                //Indicate the updating item instance
                //alter the modified status flag for this instance

                context.Entry<SpecialEvent>(context.SpecialEvents.Attach(item)).State = System.Data.Entity.EntityState.Modified;
                //command is not executed untill it is actually saved
                context.SaveChanges();
            }
        }
コード例 #30
0
        public void SpecialEvents_Add(SpecialEvent item)
        {
            using (eRestaurantContext context = new eRestaurantContext())
            {
                //create a pointer variable for the instance type
                //set this pointer to null
                SpecialEvent added = null;

                //set up the add request for the dbcontext
                added = context.SpecialEvents.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();

            }
        }