/// <summary> /// Adds new Restaurant Tables Booking Record to DataBase /// </summary> /// <param name="thebooking">The RestaurantBooking for which these bookings are being done</param> /// <exception cref="ArgumentOutOfRangeException"></exception> /// <exception cref="ArgumentNullException"></exception> /// <returns>Returns true if operation is successful otherwise returns false</returns> public bool Add(RestaurantBooking thebooking) { if (thebooking == null) { throw new ArgumentNullException("thebooking"); } if (thebooking.BookingId < 1) { throw new ArgumentOutOfRangeException("thebooking", thebooking.BookingId, "A new Menu Item Booking record can not be added for a booking with invalid Id"); } var res = 0; using (var cn = new SqlConnection(DatabaseConnection.ConnectionStringToDb)) { foreach (var table in thebooking.BookedTables) { using (var cmd = new SqlCommand("AddTableBookings", cn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@BOOKINGID", SqlDbType.BigInt).Value = thebooking.BookingId; cmd.Parameters.Add("@TABLEID", SqlDbType.BigInt).Value = table.TableId; cmd.Parameters.Add("@BOOKEDFOR", SqlDbType.DateTime).Value = thebooking.BookedFor.ToUniversalTime(); cmd.Parameters.Add("@BOOKEDTILL", SqlDbType.DateTime).Value = thebooking.BookedTill.ToUniversalTime(); if (cn.State != ConnectionState.Open) { cn.Open(); } res += cmd.ExecuteNonQuery(); } } } return(res == thebooking.BookedTables.Count); }
protected void btnAdd_Click(object sender, EventArgs e) { DateTime?date = null; try { date = DateTime.ParseExact(txtDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture); } catch { } var agencyId = -1; try { agencyId = Int32.Parse(agencySelector.Value); } catch { } var agency = BookingAddingBLL.AgencyGetById(agencyId); var restaurantBooking = new RestaurantBooking() { Date = date, Agency = agency, Status = 1, PartOfDay = 2, }; BookingAddingBLL.RestaurantBookingSaveOrUpdate(restaurantBooking); Response.Redirect("BookingViewing.aspx?NodeId=1&SectionId=15&bi=" + restaurantBooking.Id); }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var user = await _userManager.FindByNameAsync(_userAccessor.GetCurrentUsername()); var booking = new RestaurantBooking { RestaurantBookingId = request.RestaurantBookingId, BookingDate = DateTime.Now, ProductId = Guid.Parse(request.ProductId), ClientName = user != null ? user.UserName : request.ClientName, MealDate = DateTime.Parse(request.MealDate), People = request.People, MealTime = request.MealTime }; _context.RestaurantBookings.Add(booking); var success = await _context.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new System.Exception("Problem saving changes"); }
/// <summary> /// Updates the Available Record with new Details /// </summary> /// <param name="thebooking">The RestaurantBooking instance for which these bookings are being done</param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentOutOfRangeException"></exception> /// <returns>Returns true if operation is successful otherwise returns false</returns> /// <remarks>This method actually deleates all the record with the specified booking id and calls Add() method</remarks> public bool Update(RestaurantBooking thebooking) { if (thebooking == null) { throw new ArgumentNullException("thebooking"); } if (thebooking.BookingId < 1) { throw new ArgumentOutOfRangeException("thebooking", thebooking.BookingId, "A new Table Booking record can not be Updated for a booking with invalid BookingId"); } return(Delete(thebooking.BookingId) && Add(thebooking)); }
public ActionResult BookRestaurant(RestaurantBooking booking) { // RestaurantName & ID are passed hidden Restaurant restaurant = foodRepository.GetRestaurant(booking.RestaurantId); Event selectedevent = eventRepository.GetEvent(booking.SelectedEvent); if (ModelState.IsValid) { if (selectedevent.CurrentTickets != 0 && (booking.AdultTickets + booking.ChildTickets) <= selectedevent.CurrentTickets) { Ticket ticket = new Ticket(); ticket.Amount = booking.AdultTickets + booking.ChildTickets; ticket.EventId = booking.SelectedEvent; ticket.Event = eventRepository.GetEvent(ticket.EventId); ticket.Price = (booking.AdultTickets * restaurant.PriceAdults) + (booking.ChildTickets * restaurant.PriceChildren); ticket.SpecialRequest = booking.SpecialRequest; // Create session if it doesn't exist or add ticket to existing session if (Session["currentTickets"] == null) { List <Ticket> tickets = new List <Ticket>(); tickets.Add(ticket); Session["CurrentTickets"] = tickets; } else { List <Ticket> sessionTickets = (List <Ticket>)Session["currentTickets"]; sessionTickets.Add(ticket); } BookingResult resultViewModel = new BookingResult(booking.RestaurantName, ticket.Event.StartTime, ticket.Event.EndTime, ticket.SpecialRequest); return(RedirectToAction("BookEventSuccess", resultViewModel)); } ModelState.AddModelError("", "There are only " + selectedevent.CurrentTickets + " tickets available"); } // Validation failed, reload some data: booking.Events = foodRepository.GetAllFoodEvents(restaurant.RestaurantID); return(PartialView("BookEvent", booking)); }
public ActionResult BookRestaurant(int restaurantId) { // Create Viewmodel RestaurantBooking booking = new RestaurantBooking(); booking.Events = foodRepository.GetAllFoodEvents(restaurantId); Restaurant restaurant = foodRepository.GetRestaurant(restaurantId); booking.RestaurantName = restaurant.RestaurantName; booking.ChildrenPrice = restaurant.PriceChildren; booking.AdultPrice = restaurant.PriceAdults; // Get the correct timespan: TimeSpan timeAtRestaurant = booking.Events.First().EndTime.Subtract(booking.Events.First().StartTime); booking.TimeAvailable = String.Format("{0:00}:{1:00}", timeAtRestaurant.Hours, timeAtRestaurant.Minutes); // Pass ID value of restaurant: booking.RestaurantId = restaurantId; return(PartialView("BookEvent", booking)); }
public void RestaurantBookingSaveOrUpdate(RestaurantBooking restaurantBooking) { RestaurantBookingRepository.SaveOrUpdate(restaurantBooking); }
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()); } }