public ActionResult Index()
    {
        var model = new PreferencesShoppingCartViewModel
        {
            CartItemPreferences = new List <CartItemPreference>
            {
                new CartItemPreference {
                    CartItem = new CartItem {
                        Sample = "Sample 1"
                    }
                },
                new CartItemPreference {
                    CartItem = new CartItem {
                        Sample = "Sample 2"
                    }
                }
            },
            PreferenceOptions = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "Option 1", Value = "1"
                },
                new SelectListItem {
                    Text = "Option 2", Value = "2"
                },
                new SelectListItem {
                    Text = "Option 3", Value = "3"
                }
            }
        };

        return(View(model));
    }
Esempio n. 2
0
        public ActionResult Checkout(PreferencesShoppingCartViewModel viewModel)
        {
            User         user         = db.Users.FirstOrDefault(u => u.Username.Equals(User.Identity.Name, StringComparison.CurrentCultureIgnoreCase));
            ShoppingCart shoppingCart = db.Customers.FirstOrDefault(u => u.UserId.Equals(user.Id)).ShoppingCart;

            foreach (var preference in viewModel.CartItemPreferences)
            {
                CartItem cI = shoppingCart.CartItems.Find(x => x.Id.Equals(preference.CartItemId));
                cI.SeatPreference = int.Parse(preference.Selected);
                db.CartItems.AddOrUpdate(cI);
                db.SaveChanges();
            }

            Order order = shoppingCart.CreateOrder();

            if (order != null)
            {
                TempData["Message"] = "Successfully ordered.";
            }
            else
            {
                TempData["Message"] = "Unsuccessful order.";
                return(RedirectToAction("Index"));
            }

            return(View(order));
        }
Esempio n. 3
0
        public ActionResult Preferences(IndexShoppingCartViewModel viewModel)
        {
            User         user         = db.Users.FirstOrDefault(u => u.Username.Equals(User.Identity.Name, StringComparison.CurrentCultureIgnoreCase));
            ShoppingCart shoppingCart = db.Customers.FirstOrDefault(u => u.UserId.Equals(user.Id)).ShoppingCart;

            if (!shoppingCart.AreTicketsAvailable())
            {
                TempData["Message"] = "There is not enough of tickets for selected trips.";
                return(RedirectToAction("Index"));
            }

            var cartItemPreferences = new List <PreferencesShoppingCartViewModel.CartItemPreference>();

            shoppingCart.CartItems.ForEach(cartI => cartItemPreferences.Add(new PreferencesShoppingCartViewModel.CartItemPreference()
            {
                CartItemId = cartI.Id,
                Title      = cartI.Trip.Title
            }));
            var viewModelNew = new PreferencesShoppingCartViewModel()
            {
                CartItemPreferences = cartItemPreferences
            };

            viewModelNew.PreferenceOptions = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Value = "0",
                    Text  = "Random"
                },
                new SelectListItem()
                {
                    Value = "1",
                    Text  = "Adjacent"
                },
                new SelectListItem()
                {
                    Value = "2",
                    Text  = "In the middle"
                },
                new SelectListItem()
                {
                    Value = "3",
                    Text  = "Window seat"
                }
            };
            return(View(viewModelNew));
        }
    public ActionResult Index(PreferencesShoppingCartViewModel model)
    {
        // Do something

        return(View(model));
    }