public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { SimplePlan currentSimplePlan = null; if (controllerContext.HttpContext.Session != null) { currentSimplePlan = (SimplePlan)controllerContext.HttpContext.Session[nameof(currentSimplePlan)]; } if (currentSimplePlan == null) { var appSetting = ConfigurationManager.AppSettings["Plan.Api"]; var plan = new PlanProcessor(appSetting).GetPlan(); if (plan.ResponseCode != 0) { throw new Exception($"The plan is not valid! ({nameof(plan.ResponseCode)}: {plan.ResponseCode})"); } currentSimplePlan = new SimplePlan(plan); if (controllerContext.HttpContext.Session != null) { controllerContext.HttpContext.Session[nameof(currentSimplePlan)] = currentSimplePlan; } } return(currentSimplePlan); }
private static PlanIndexViewModel CreateModel(SimplePlan currentSimplePlan, Order currentOrder) { var model = new PlanIndexViewModel { Plan = currentSimplePlan, Order = currentOrder }; return(model); }
public RedirectToRouteResult RemoveTicket(SimplePlan currentSimplePlan, Order currentOrder, int seatCompositeId) { var found = currentOrder.Tickets.FirstOrDefault(t => t.Seat.CompositeId == seatCompositeId); if (found != null) { currentOrder.Tickets.Remove(found); } return(RedirectToAction("Index", CreateModel(currentSimplePlan, currentOrder))); }
public RedirectToRouteResult AddTicket(SimplePlan currentSimplePlan, Order currentOrder, int seatCompositeId) { var ticket = new Ticket { Seat = currentSimplePlan.GetSeatsLayout() .OfType <Seat>() .FirstOrDefault(s => s.CompositeId == seatCompositeId) }; currentOrder.Tickets.Add(ticket); return(RedirectToAction("Index", CreateModel(currentSimplePlan, currentOrder))); }
public ViewResult Checkout(SimplePlan currentSimplePlan, Order currentOrder) { if (!currentOrder.Tickets.Any()) { ModelState.AddModelError(string.Empty, "Sorry, your order is empty!"); } if (ModelState.IsValid) { currentOrder.OrderNumber = Guid.NewGuid().ToString(); currentOrder.OrderDate = DateTime.Now; _orderRepository.SaveOrder(currentOrder); currentOrder.Tickets.Clear(); return(View("Completed")); } return(View("Index", CreateModel(currentSimplePlan, currentOrder))); }
public ViewResult Index(SimplePlan currentSimplePlan, Order currentOrder) { return(View(CreateModel(currentSimplePlan, currentOrder))); }