public IActionResult AddToShoppingBag([FromForm] DetailPageModel model) { //Create the customer var userId = _userManager.GetUserId(User); var customer = GetCustomer(userId); //Get the bike var bike = GetProduct(model.Product.Id); //Create the shoppingBag if it not exists var shoppingBag = GetShoppingBag(customer.Id); var shoppingItem = _shoppingItemRepository.GetItem(model.Product.Id, shoppingBag.Id); if (shoppingItem == null) { shoppingItem = CreateShoppingItem(bike, model.ShoppingItem.Quantity, shoppingBag); _shoppingItemRepository.AddItem(shoppingItem); } else { shoppingItem.Quantity += model.ShoppingItem.Quantity; _shoppingItemRepository.UpdateShoppingItem(shoppingItem); } //TempData.Put("_ShoppingBag", shoppingBag); return(RedirectToAction("Index", "ShoppingBag")); }
public async Task <IActionResult> Details(int?id) { if (!id.HasValue) { return(NotFound()); } if (!await _sessionBL.SessionExists(id.Value)) { return(NotFound()); } var pageModel = new DetailPageModel(); pageModel.Session = await _sessionBL.GetSessionViewModels(id.Value, UserId); if (pageModel.Session == null) { return(NotFound()); } pageModel.Speakers = await _speakerBL.GetSpeakersForSession(pageModel.Session.SessionId); return(View(pageModel)); }
public IActionResult Details(int bikeId) { var bike = _productRepository.GetBikeById(bikeId); if (bike == null) { return(NotFound()); } var detailPageModel = new DetailPageModel { Product = bike, ShoppingItem = new ShoppingItem() }; //var image = detailPageModel.Product.Image; return(View(detailPageModel)); }