public async Task <IActionResult> OnGetAsync(string productId) { if (string.IsNullOrEmpty(productId)) { return(NotFound()); } Product = await _productApi.GetProduct(productId); if (Product == null) { return(NotFound()); } return(Page()); }
public IDomainResult Handle(AddItemCommand command) { var cart = cartRepository.GetByCustomerId(command.CustomerId) ?? new Cart(new Customer(command.CustomerId, CustomerStatus.Standard)); var productApiRetry = Policy .Handle <Exception>() .WaitAndRetry( retryStrategy.RetryCount, attempt => TimeSpan.FromMilliseconds(retryStrategy.WaitMilliseconds)); Apis.ProductInfo productInfo = null; try { productInfo = productApiRetry.Execute(() => productApi.GetProduct(command.ProductId)); } catch (Exception e) { logger.LogError(e); return(new ServiceUnavailableError()); } if (productInfo == null) { return(new ProductDoesNotExistError()); } cart.AddItem(command.ProductId, productInfo.ProductName, productInfo.Price); cartRepository.Save(cart); return(new OkResult <Cart>(cart)); }
public async Task <IActionResult> OnPostAddToCartAsync(string productId) { //if (!User.Identity.IsAuthenticated) // return RedirectToPage("./Account/Login", new { area = "Identity" }); var product = await _productApi.GetProduct(productId); var item = new CartItem() { ProductId = product.Id, ProductName = product.Name, Quantity = 1, Color = "Red", Price = product.Price }; await _basketApi.AddItem("test", item); return(RedirectToPage("Cart")); }
public async Task <IActionResult> OnPostAddToCartAsync(string productId) { //if (!User.Identity.IsAuthenticated) // return RedirectToPage("./Account/Login", new { area = "Identity" }); username = HttpContext.Session.GetString("username"); if (string.IsNullOrEmpty(username)) { return(RedirectToPage("Login", new { loginError = "Please sign in" })); } var item = await _productApi.GetProduct(productId); await _basketApi.AddItem(username, new CartItem { ProductId = productId, Color = "Black", Price = item.Price, Quantity = 1, ProductName = item.Name }); return(RedirectToPage("Cart")); }
public async Task <IActionResult> OnPostAddToCartAsync(string productId) { string username = HttpContext.Session.GetString("username"); if (string.IsNullOrEmpty(username)) { return(RedirectToPage("Login", new { loginError = "Please sign in" })); } var product = await _productApi.GetProduct(productId); var item = new CartItem { ProductId = product.Id, Price = product.Price, ProductName = product.Name, Quantity = 1 }; await _basketApi.AddItem(username, item); return(RedirectToPage("Cart")); }