public async Task <CheckoutSummary> Checkout(string userId) { var result = new CheckoutSummary() { Date = DateTime.UtcNow, Products = new List <CheckoutProduct>() }; IUserActor actor = CreateUserActor(userId); var cart = await actor.GetCart(); IProductCatalogService productCatalogService = GetProductCatalogService(); var products = await productCatalogService.GetAllProducts(); var totalCost = 0.0; foreach (var item in cart) { var productId = item.Key; var quantity = item.Value; var product = products.FirstOrDefault(p => p.Id == productId); if (product != null) { result.Products.Add(new CheckoutProduct() { Product = product, Quantity = quantity, Price = product.Price * quantity }); totalCost += (product.Price * quantity); } } result.TotalPrice = totalCost; //Clearing the cart since user has checkout all the products and add to history await actor.ClearCart(); await AddToHistory(result); return(result); }
public async Task DeleteCart([FromQuery] string userId) { CreateActor(userId); await _userActor.ClearCart(); }