public async Task <CheckoutSummary> Checkout(string userId) { var result = new CheckoutSummary(); //call user actor to get the basket IUserActor userActor = GetUserActor(userId); Dictionary <Guid, int> basket = await userActor.GetBasket(); //get catalog client IProductCatalogService catalogService = GetProductCatalogService(); //constuct CheckoutProduct items by calling to the catalog foreach (KeyValuePair <Guid, int> basketLine in basket) { Product product = await catalogService.GetProduct(basketLine.Key); var checkoutProduct = new CheckoutProduct { Product = product, Price = product.Price, Quantity = basketLine.Value }; result.Products.Add(checkoutProduct); } //generate total price result.TotalPrice = result.Products.Sum(p => p.Price); //clear user basket await userActor.ClearBasket(); await AddToHistory(result); return(result); }
public async Task <CheckoutSummary> CheckoutAsync(string userId) { var result = new CheckoutSummary(); result.Date = DateTime.UtcNow; result.Products = new List <CheckoutProduct>(); IUserActor userActor = GetUserActor(userId); BasketItem[] basket = await userActor.GetBasket(); var catalogService = GetProductCatalogService(); foreach (var basketLine in basket) { var product = await catalogService.GetProduct(basketLine.ProductId); var checkoutProduct = new CheckoutProduct { Product = product, Price = product.Price, Quantity = basketLine.Quantity }; result.Products.Add(checkoutProduct); } result.TotalPrice = result.Products.Sum(p => p.Price); await userActor.ClearBasket(); await AddToHistoryAsync(result); return(result); }
public async Task <CheckoutSummary> Checkout(string userId) { var result = new CheckoutSummary(); result.Date = DateTime.UtcNow; result.Products = new List <CheckoutProduct>(); IUserActor userActor = GetUserActor(userId); Dictionary <Guid, int> basket = await userActor.GetBasket(); IProductCatalogService catalogService = GetProductCatalogService(); foreach (KeyValuePair <Guid, int> basketLine in basket) { Product product = await catalogService.GetProduct(basketLine.Key); var checkoutProduct = new CheckoutProduct { Product = product, Price = product.Price, Quantity = basketLine.Value }; result.Products.Add(checkoutProduct); } result.TotalPrice = result.Products.Sum(p => p.Price); await userActor.ClearBasket(); await AddToHistory(result); return(result); }
public async Task <CheckoutSummary> CheckoutAsync(string userId) { //holds result of the checkout var result = new CheckoutSummary(); result.Date = DateTime.UtcNow; result.Products = new List <CheckoutProduct>(); //call user actor to get the basket IUserActor userActor = GetUserActor(userId); BasketItem[] basket = await userActor.GetBasket(); //get catalog client IProductCatalogService catalogService = GetProductCatalogService(); //get detailed product information for each basket item by calling product service foreach (BasketItem basketLine in basket) { Product product = await catalogService.GetProductAsync(basketLine.ProductId); var checkoutProduct = new CheckoutProduct { Product = product, Price = product.Price, Quantity = basketLine.Quantity }; result.Products.Add(checkoutProduct); } //generate total price result.TotalPrice = result.Products.Sum(p => p.Price); //clear user basket await userActor.ClearBasket(); await AddToHistoryAsync(result); return(result); }
public async Task Delete(string userId) { IUserActor actor = GetActor(userId); await actor.ClearBasket(); }