public async Task AddItemToCartAsync(ApplicationUser user, CartItem product) { Cart cart = await GetCartAsync(user); _logger.LogDebug("user name" + user.Id); //if nothing in cart Create Cart if (cart == null) { cart = new Models.CartModels.Cart() { BuyerId = user.Id, Items = new List <CartItem>() }; } var cartItem = cart.Items .Where(p => p.ProductId == product.ProductId) .FirstOrDefault(); if (cartItem == null) { cart.Items.Add(product); } else { cartItem.Quantity += 1; } await UpdateCartAsync(cart); }
public async Task <IViewComponentResult> InvokeAsync(ApplicationUser user) { var vm = new Models.CartModels.Cart(); try { vm = await _service.GetCartAsync(user); return(View(vm)); } catch (Exception) { ViewBag.IsCartInoperative = true; TempData["CartInoperativeMsg"] = "Cart Service is inoperative, please retry later."; } return(View(vm)); }
public async Task <IViewComponentResult> InvokeAsync(ApplicationUser user) { var vm = new Models.CartModels.Cart(); try { vm = await _cartSvc.GetCart(user); return(View(vm)); } catch (BrokenCircuitException) { // Catch error when CartApi is in open circuit mode ViewBag.IsBasketInoperative = true; TempData["BasketInoperativeMsg"] = "Basket Service is inoperative, please try later on. (Business Msg Due to Circuit-Breaker)"; } return(View(vm)); }