示例#1
0
        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 ProductController(IMapper mapper)
        {
            _catalogService = ProductCatalogServiceResolver.Resolve();

            _mapper = mapper;
        }