// GET: ShoppingCart public ActionResult Index() { User user = db.Users.FirstOrDefault(u => u.Username.Equals(User.Identity.Name, StringComparison.CurrentCultureIgnoreCase)); //Get currently logged in user ShoppingCart shoppingCart = db.Customers.FirstOrDefault(u => u.UserId.Equals(user.Id)).ShoppingCart; //Get customer associated with logged in customer IndexShoppingCartViewModel shoppingCartViewModel = new IndexShoppingCartViewModel() { ShoppingCart = shoppingCart, Total = shoppingCart.GetTotal() }; return(View(shoppingCartViewModel)); }
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 async Task <IActionResult> Index() { var products = from product in await _shoppingCart.Products() group product by product into grouping orderby grouping.Key.Name ascending select new IndexShoppingCartItemViewModel { Id = grouping.Key.Id, Name = grouping.Key.Name, Price = grouping.Key.Price, Quantity = grouping.Count() }; var total = await _shoppingCart.Total(); var viewModel = new IndexShoppingCartViewModel { Products = products, Total = total }; return(View(viewModel)); }