public void UpdateSpecialEvent(SpecialEvent Entities)
 {
     using(RestaurantContext specialEventDBContext = new RestaurantContext())
     { var updating = specialEventDBContext.SpecialEvents.Attach(Entities);
     var matchingWithExistingValues = specialEventDBContext.Entry<SpecialEvent>(updating);
     matchingWithExistingValues.State = System.Data.Entity.EntityState.Modified;
     specialEventDBContext.SaveChanges();
     }
 }
        public void UpdateSpecialEvent(SpecialEvent item)
        {
            using ( RestaurantContext context = new RestaurantContext())
                {
                    //First attach the item to the dbContext collection
                    var attached = context.SpecialEvents.Attach(item);
                    //Second,get the entry for existing data that should match for
                    //this specific special event
                    var existing = context.Entry<SpecialEvent>(attached);
                    //Third,mark that the object's values have changed
                    existing.State = System.Data.Entity.EntityState.Modified;

                    //Lastly,save the changes in the database
                    context.SaveChanges();
                }
        }
        public void DeactivateSpecialEvent(SpecialEvent item)
        {
            using (var context = new RestaurantContext())
            {
                // First, get a reference to the actual item in the Db
                // Find() is a method to look up an item by it's primary key.
                var existing = context.SpecialEvents.Find(item.EventCode);

                // Second, remove the item from the database context
                existing.Active = false; // Modifies the property on the SpecialEvent
                var updatable = context.Entry(existing); // Get a reference to the special event as an Entity in the database context
                // Specify a particular property as being changed.
                updatable.Property(x => x.Active).IsModified = true;

                // Lastly, save the changes to the database
                context.SaveChanges();
            }
        }
        public void UpdateSpecialEvent(SpecialEvent item)
        {
            using (RestaurantContext context = new RestaurantContext())
            {
                //First attach the item to the dbContext collection
                var attached = context.SpecialEvents.Attach(item);

                // var matchingWithExistingValues = context.Entry<SpecialEvent>(attached);
                //matchingWithExistingValues.State = System.Data.Entity.EntityState.Modified;
                //context.SaveChanges();

                var existing = context.Entry<SpecialEvent>(attached);
                existing.State = System.Data.Entity.EntityState.Modified;

                context.SaveChanges();

            }
            //First attacj the item to the dbContext collection
        }
 public void SeatCustomer(DateTime when, int reservationId, List<byte> tables, int waiterId)
 {
     var availableSeats = AvailableSeatingByDateTime(when.Date, when.TimeOfDay);
     using (var context = new RestaurantContext())
     {
         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 Exception("Unable to seat customer");
         // 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);
 }