public ActionResult Basket() { BasketViewModel vm = new BasketViewModel(); if ((Reservation)Session["Reservation"] != null) { reservation = (Reservation)Session["Reservation"]; } if (reservation != null) { if (reservation.Tickets != null) { vm.Tickets = reservation.Tickets; } if (reservation.PassParToutDays != null) { vm.Partoutdays = reservation.PassParToutDays; } if (reservation.PassParToutWeek != null) { vm.ParToutWeek = reservation.PassParToutWeek; } decimal totalPrice = 0; if (vm.Tickets != null) { foreach (BaseTicket bt in vm.Tickets) { if (bt is ConcertTicket) { ConcertTicket ct = bt as ConcertTicket; totalPrice += ct.Ticket.Count * ct.Concert.Hall.Price; } if (bt is DinnerTicket) { DinnerTicket dt = bt as DinnerTicket; totalPrice += dt.Ticket.Count * dt.Restaurant.Price; } } } if (vm.Partoutdays != null) { foreach (PassParToutDay pd in vm.Partoutdays) { decimal dayPrice = passPartoutTypeRepository.GetPassPartoutType(1).Price; totalPrice += pd.Count * dayPrice; } } if (vm.ParToutWeek != null) { decimal weekPrice = passPartoutTypeRepository.GetPassPartoutType(4).Price; totalPrice += vm.ParToutWeek.Count * weekPrice; } vm.TotalPrice = (double)totalPrice; } return(View(vm)); }
public ActionResult Reservation(FormCollection collection) { //check if session is already set and set of new reservation or load from session if (Session["Reservation"] != null) { reservation = (Reservation)Session["Reservation"]; } else { reservation = new Reservation(); } DinnerSession selectedDinnerSession = new DinnerSession(); //get input from user from the Collection that's passed from the view int amount = Convert.ToInt32(collection.Get("ticket-amount")); int dayId = Convert.ToInt32(collection.Get("day")); DateTime timeSlot = Convert.ToDateTime(collection.Get("timeslot")); int restaurantId = Convert.ToInt32(collection.Get("restaurantId")); string remarks = collection.Get("remarks"); Restaurant restaurant = restaurantRepository.GetRestaurant(restaurantId); //get dinnerSessions by restaurantId and timeslot the customer selected List <DinnerSession> dinnerSession = dinnerSessionRepository.getDinnerSessionsByRestaurantAndStartTime(restaurantId, timeSlot).ToList(); //check for each session in the dinnersession list if the dayId matches the selected dayId by the customer foreach (DinnerSession session in dinnerSession) { if (session.DayId == dayId) { selectedDinnerSession = session; } } //fill dinnerTicket and PreTicket DinnerTicket dinnerTicket = new DinnerTicket { Ticket = new PreTicket { Id = 1, EventId = selectedDinnerSession.EventId, Event = eventRepository.GetEvent(selectedDinnerSession.EventId), Count = amount }, Restaurant = restaurant, Remarks = remarks, Count = amount, Id = selectedDinnerSession.EventId }; //create new list of Tickets if reservation doesn't contain any. if (reservation.Tickets == null) { reservation.Tickets = new List <BaseTicket>(); } reservation.Tickets.Add(dinnerTicket); Session["Reservation"] = reservation; return(RedirectToAction("Basket", "Home")); }