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);
        }
Пример #2
0
        private static PlanIndexViewModel CreateModel(SimplePlan currentSimplePlan, Order currentOrder)
        {
            var model = new PlanIndexViewModel
            {
                Plan  = currentSimplePlan,
                Order = currentOrder
            };

            return(model);
        }
Пример #3
0
        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)));
        }
Пример #4
0
        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)));
        }
Пример #5
0
        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)));
        }
Пример #6
0
 public ViewResult Index(SimplePlan currentSimplePlan, Order currentOrder)
 {
     return(View(CreateModel(currentSimplePlan, currentOrder)));
 }