public async Task <ActionResult> UpdateItem(Guid productId, int quantity) { var product = await _catalogService.GetById(productId); if (!ProductIsValid(product, productId)) { return(View(nameof(Index), await _shoppingCartService.Get())); } if (!ProductQuantityIsValid(product, quantity)) { return(View(nameof(Index), await _shoppingCartService.Get())); } var item = new ItemShoppingCartViewModel { ProductId = productId, Quantity = quantity }; var response = await _shoppingCartService.Put(productId, item); if (HasResponseErrors(response)) { return(View(nameof(Index), await _shoppingCartService.Get())); } return(RedirectToAction(nameof(Index))); }
public async Task <ActionResult> AddItem(ItemShoppingCartViewModel item) { var product = await _catalogService.GetById(item.ProductId); if (!ProductIsValid(product, item.ProductId)) { return(View(nameof(Index), await _shoppingCartService.Get())); } if (!ProductQuantityIsValid(product, item.Quantity)) { return(View(nameof(Index), await _shoppingCartService.Get())); } item.Name = product.Name; item.Image = product.Image; item.Value = product.Value; var response = await _shoppingCartService.Post(item); if (HasResponseErrors(response)) { return(View(nameof(Index), await _shoppingCartService.Get())); } return(RedirectToAction(nameof(Index))); }