示例#1
0
        public async Task <CheckoutSummary> CheckoutAsync(string userId)
        {
            var result = new CheckoutSummary();

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

            //get user basket
            var userActor = GetUserActor(userId);
            Dictionary <Guid, int> basket = await userActor.GetBasket();

            //get catalogClient
            IProductCatalogService catalogService = GetProductCatalogService();

            foreach (var item in basket)
            {
                Product product = await catalogService.GetProduct(item.Key);

                result.Products.Add(
                    new CheckoutProduct
                {
                    Product  = product,
                    Price    = product.Price,
                    Quantity = item.Value
                });
            }
            await userActor.ClearBasket();

            await AddToHistoryAsync(result);

            return(result);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        public async Task <CheckoutSummary> CheckoutAsync(string userId)
        {
            var result = new CheckoutSummary();

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

            // Get the user basket
            IUserActor userActor = GetUserActor(userId);

            BasketItem[] basket = await userActor.GetBasket();

            IProductCatalogService catalogService = GetProductCatalogService();

            foreach (var item in basket)
            {
                var product = await catalogService.GetProduct(item.ProductId);

                var checkoutProduct = new CheckoutProduct()
                {
                    Product  = product,
                    Price    = product.Price,
                    Quantity = item.Quantity
                };

                result.Products.Add(checkoutProduct);
            }

            return(result);
        }
示例#5
0
        public async Task <IHttpActionResult> GetProduct(string productId)
        {
            var guid    = Guid.Parse(productId);
            var product = await _catalogService.GetProduct(guid);

            if (product != null)
            {
                return(Ok(Mapper.Map <Product, ProductDTO>(product)));
            }
            else
            {
                return(NotFound());
            }
        }
        public ActionResult Detail(int id)
        {
            ProductDetailView productDetailView = new ProductDetailView();
            GetProductRequest request           = new GetProductRequest()
            {
                ProductId = id
            };
            GetProductResponse response    = _productService.GetProduct(request);
            ProductView        productView = response.Product;

            productDetailView.Product    = productView;
            productDetailView.Categories = base.GetCategories();
            return(View(productDetailView));
        }
示例#7
0
        public async Task <IEnumerable <ApiProduct> > GetProduct()
        {
            var products = await _productCatalogService.GetProduct();

            return(products.Select <Product, ApiProduct>(product =>
            {
                return new ApiProduct()
                {
                    Name = product.Name,
                    Avialability = product.Avialability > 0,
                    ProductID = product.ProductID,
                    Description = product.Description,
                    Price = product.Price
                };
            }));
        }
示例#8
0
        public ActionResult <ProductDetailView> Detail(int id)
        {
            var productDetailView = new ProductDetailView();
            var request           = new GetProductRequest()
            {
                ProductId = id
            };
            var response    = _productService.GetProduct(request);
            var productView = response.Product;

            productDetailView.Product       = productView;
            productDetailView.BasketSummary = base.GetBasketSummaryView();
            productDetailView.Categories    = base.GetCategories();

            return(productDetailView);
        }
示例#9
0
        public async Task <CheckoutSummary> Checkout(string userId)
        {
            var result = new CheckoutSummary();

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

            //call user actor to get the basket
            var userActor = GetUserActor(userId);
            var basket    = await userActor.GetBasket();

            //get catalog client
            IProductCatalogService catalogService = GetProductCatalogService();

            //constuct CheckoutProduct items by calling to the catalog
            foreach (var basketLine in basket)
            {
                var product = await catalogService.GetProduct(basketLine.Key);

                if (product != null)
                {
                    var checkoutProduct = new CheckoutProduct
                    {
                        Product  = product,
                        Price    = product.Price,
                        Quantity = basketLine.Value
                    };
                    result.Products.Add(checkoutProduct);
                }
            }

            //generate total price
            result.TotalPrice = result.Products.Select(p => p.Quantity * p.Price).Sum();

            //clear user basket
            await userActor.ClearBasket();

            await AddToHistory(result);

            return(result);
        }
 public async Task <ApiProduct> Get(Guid id)
 {
     return(_mapper.Map <ApiProduct>(await _catalogService.GetProduct(id)));
 }
 public async Task <ActionResult> Details(Guid id)
 {
     return(View(await _service.GetProduct(id)));
 }