public ActionResult UpdateReservation(Reservation reservation)
 {
     if (ModelState.IsValid)
     {
         var restaurant = db.Restaurants.Find(reservation.RestaurantId);
         if (reservation != null)
         {
             var reserve = db.Reservations.Find(reservation.Id);
             db.Reservations.Remove(reserve);
             if (restaurant.AutoIncrement)
                 restaurant.WaitTime = restaurant.WaitTime.Subtract(new TimeSpan(restaurant.Increment.Ticks * reserve.Guests));
             db.SaveChanges();
             return PartialView("ViewReservation", restaurant.Reservations);
         }
     }
     return PartialView();
 }
Exemple #2
0
 public Restaurant Reserve(Reservation reservation)
 {
     try
     {
         var restaurant = db.Restaurants.Where(r => r.Id == reservation.RestaurantId).SingleOrDefault();
         if (restaurant != null)
         {
             db.Reservations.Add(reservation);
             if (restaurant.AutoIncrement)
                 restaurant.WaitTime = restaurant.WaitTime.Add(new TimeSpan((restaurant.Increment.Ticks * reservation.Guests)));
             db.SaveChanges();
             restaurant.Reservations = db.Reservations.Where(r => r.RestaurantId == restaurant.Id).ToList();
             return restaurant;
         }
         else
             throw new FaultException("Restaurant doesn't exist");
     }
     catch (Exception err)
     {
         throw new FaultException("Error accessing the database");
     }
 }
 public ActionResult Reserve(Reservation model)
 {
     if (ModelState.IsValid)
     {
         var restaurant = db.Restaurants.Where(r => r.Id == model.RestaurantId).SingleOrDefault();
         if (restaurant != null)
         {
             db.Reservations.Add(model);
             if (restaurant.AutoIncrement)
                 restaurant.WaitTime = restaurant.WaitTime.Add(new TimeSpan((restaurant.Increment.Ticks * model.Guests)));
             db.SaveChanges();
             ViewBag.Message = "Your reservation was added";
             return PartialView();
         }
         else
         {
             ViewBag.Message = "Error adding reservation: no restaurant set";
             return PartialView();
         }
     }
     ViewBag.Message = "There was an error adding your reservation";
     return PartialView();
 }