public ActionResult New(BookingViewModel model, int? offerid)
 {
     try
     {
         IEnumerable<RestaurantMenuItem> restaurantMenuItems;
         IEnumerable<RestaurantTable> restaurantTables;
         SeasonalOffer restaurantOffer;
         BookingHelper.ValidateModel(this, model, offerid, out restaurantMenuItems, out restaurantTables, out restaurantOffer);
         if (ModelState.IsValid)
         {
             TempData[TempDataStringResuorce.NewBookingData] = new TempDataConfirmBooking { Model = model, OfferId = offerid ?? -1};
             return Request.IsAuthenticated ? RedirectToAction("Confirm", "Bookings") : RedirectToAction("RegisterGuest", "Account", new {returnurl = Url.Action("Confirm")});
         }
         // If we got this far, something failed, redisplay form
         TempData[TempDataStringResuorce.ActionResultNotification] = new ActionResultNotification
         {
             Message = ModelState.ContainsKey("addstatus") ? ModelState["addstatus"].Errors[0].ErrorMessage : "There was an Error in making you booking, please try again !",
             Result = false,
             State = ActionResultNotification.MessageState.Error
         };
         return View(model);
     }
     catch (Exception e)
     {
         var result = new ActionResultNotification
                          {
                              Result = false,
                              Message = e.Message,
                              State = ActionResultNotification.MessageState.Error
                          };
         if (Request.IsAjaxRequest())
             return Json(result);
         TempData[TempDataStringResuorce.ActionResultNotification] = result;
         return View();
     }
 }
        public ActionResult Confirm(string couponcode)
        {
            var tmpdata = TempData.Peek(TempDataStringResuorce.NewBookingData) as TempDataConfirmBooking;
            try
            {
                if (tmpdata == null)
                {
                    TempData[TempDataStringResuorce.ActionResultNotification] = new ActionResultNotification
                            {
                                Result = false,
                                Message = "Invalid Booking Request, please try again !",
                                State = ActionResultNotification.MessageState.Error
                            };
                    return RedirectToAction("New");
                }

                var model = tmpdata.Model;
                if (model == null)
                {
                    TempData[TempDataStringResuorce.ActionResultNotification] = new ActionResultNotification
                    {
                        Result = false,
                        Message = "Invalid Booking Request, please try again !",
                        State = ActionResultNotification.MessageState.Error
                    };
                    return RedirectToAction("New");
                }
                var offerid = tmpdata.OfferId;
                IEnumerable<RestaurantMenuItem> restaurantMenuItems;
                IEnumerable<RestaurantTable> restaurantTables;
                SeasonalOffer restaurantOffer;
                Coupon restaurantcoupon;
                BookingHelper.ValidateModel(this, model, offerid, couponcode, out restaurantMenuItems, out restaurantTables, out restaurantOffer, out restaurantcoupon);
                if (restaurantOffer != null && restaurantcoupon != null)
                {
                    ModelState.AddModelError("addstatus", "Two or more offers cannot be clubbed together, either use a Coupon Code or a Seasonal Offer");
                }
                if (ModelState.IsValid)
                {
                    var booking = new RestaurantBooking
                                      {
                                          BookedFor = model.BookedFor.ToUniversalTime(),
                                          BookedOn = DateTime.UtcNow,
                                          BookedTill = model.BookedFor.ToUniversalTime().AddMinutes(AppConfigHelper.BookingSlotMinutes * model.BookedSlots),
                                          BookedTables = restaurantTables.ToList(),
                                          PrefferedMenuItems = restaurantMenuItems.ToList(),
                                          BookingCustomer = new AccountMembershipService().GetUser(((RestaurantUserIdentity)User.Identity).UserGuid, true)
                                      };
                    booking.Bills.Add(BookingHelper.GetBookingBill(restaurantMenuItems, restaurantTables, restaurantOffer,
                                                     restaurantcoupon, model.BookedSlots));

                    //Status of the booking is automaticaly set by repository according to availability
                    var bookingresult = Repository.Add(booking);
                    if (bookingresult > 0) TempData.Remove(TempDataStringResuorce.NewBookingData);
                    var message = bookingresult > 0
                                      ? String.Format("The Booking of Booking ID:{0} was successful", bookingresult)
                                      : String.Format("The Booking was Unsuccessful! Please try again");
                    var result = new ActionResultNotification
                    {
                        Result = bookingresult > 0,
                        Message = message,
                        State = bookingresult > 0 ? ActionResultNotification.MessageState.Information : ActionResultNotification.MessageState.Error
                    };
                    if (Request.IsAjaxRequest())
                        return Json(result);

                    TempData[TempDataStringResuorce.ActionResultNotification] = result;
                    return RedirectToAction("Index");
                }
                // If we got this far, something failed, redisplay form
                TempData[TempDataStringResuorce.ActionResultNotification] = new ActionResultNotification
                {
                    Message = ModelState.ContainsKey("addstatus") ? ModelState["addstatus"].Errors[0].ErrorMessage : "There was an Error in making you booking, please try again !",
                    Result = false,
                    State = ActionResultNotification.MessageState.Error
                };
                return View(model);
            }
            catch (Exception e)
            {
                var result = new ActionResultNotification
                {
                    Result = false,
                    Message = e.Message,
                    State = ActionResultNotification.MessageState.Error
                };
                if (Request.IsAjaxRequest())
                    return Json(result);
                TempData[TempDataStringResuorce.ActionResultNotification] = result;
                if (tmpdata != null)
                TempData[TempDataStringResuorce.NewBookingData] =
                    new TempDataConfirmBooking { Model = tmpdata.Model, OfferId = tmpdata.OfferId };
                return Confirm();
            }
        }