public ActionResult Create() { int refreshInterval = Convert.ToInt32(TempData["RefreshInterval"]); ViewBag.RefreshInterval = refreshInterval + 1; if (Session["flight"] == null || Session["flightSeats"] == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } Flight flight = Session["flight"] as Flight; List <FlightSeat> flightSeats = Session["flightSeats"] as List <FlightSeat>; //For holding the seats when user refreshes the view of the form foreach (var flightSeat in flightSeats) { if (flightSeat.IsAvailable) { flightSeat.HoldSeat(); flightSeatRepository.ModifySeats(flightSeat); } } unitOfWork.Complete(); var flightSeatIds = flightSeats.Select(fs => fs.FlightSeatId).ToArray(); var flightService = new FlightHubService(); flightService.FlightSeatsClosed(flightSeatIds); var ticketViewModels = new List <TicketFormViewModel>(); flightSeats.ForEach(fs => ticketViewModels.Add(new TicketFormViewModel(flight.FlightId, fs))); var ticketContainer = InitializeTicketContainer(ticketViewModels); var orderViewModel = new OrderTicketsFormViewModel(null, null, ticketContainer.GetTotalPrice()); var viewModel = new OrderTicketFormContainerViewModel(orderViewModel, ticketContainer, flight); return(View(viewModel)); }
public IHttpActionResult HoldSeats([FromBody] long[] seatIds) { if (seatIds == null || seatIds.Length < 1) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var seatsToRelease = flightSeatRepository.GetFlightSeatsById(seatIds); if (seatsToRelease == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } seatsToRelease.ForEach(fs => fs.HoldSeat()); unitOfWork.Complete(); var flightService = new FlightHubService(); flightService.FlightSeatsClosed(seatIds); return(Ok(seatIds)); }