Пример #1
0
        public async Task <CheckoutSummary> CheckoutAsync(string userId)
        {
            var result = new CheckoutSummary();

            result.Date     = DateTime.UtcNow;
            result.Products = new List <CheckoutProduct>();

            //call user actor to get the basket
            IUserActor             userActor = GetUserActor(userId);
            Dictionary <Guid, int> basket    = await userActor.GetBasketAsync();

            //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.GetProductAsync(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.ClearBasketAsync();

            await AddToHistory(result);

            return(result);
        }
Пример #2
0
        public async Task Delete(string userId)
        {
            IUserActor actor = GetActor(userId);

            await actor.ClearBasketAsync();
        }