public async Task <CheckoutSummary> CheckoutCart(string userId) { var result = new CheckoutSummary { Date = DateTime.UtcNow, Products = new List <CheckoutProduct>() }; var userActor = UserActorResolver.Resolve(userId); var cartItems = await userActor.GetCartItems(); var catalogService = ProductCatalogServiceResolver.Resolve(); foreach (var cartItem in cartItems) { var product = await catalogService.GetProduct(cartItem.Key); result.Products.Add(new CheckoutProduct { Product = product, Price = product.Price, Quantity = cartItem.Value }); } result.TotalPrice = result.Products.Sum(p => p.Price); await userActor.ClearCart(); await AddToHistory(result); return(result); }
public async Task <ApiCart> Get(string userId) { var products = await UserActorResolver.Resolve(userId).GetCartItems(); return(new ApiCart { UserId = userId, Items = products.Select(x => new ApiCartItem { ProductId = x.Key.ToString(), Quantity = x.Value }) }); }
public async Task Clear(string userId) { await UserActorResolver.Resolve(userId).ClearCart(); }
public async Task Add(string userId, [FromBody] ApiCartAddRequest request) { await UserActorResolver.Resolve(userId).AddToCart(request.ProductId, request.Quantity); }