public async Task <ActionResult> Index()
        {
            // Save filter string as empty to use when exporting excel
            HttpContext.Session.SetString("FilterStr", "");

            return(View(await _service.GetAllProducts()));
        }
        public async Task <IEnumerable <ApiProduct> > Get()
        {
            IEnumerable <Product> allProducts = await _catalogService.GetAllProducts();

            return(allProducts.Select(p => new ApiProduct
            {
                Id = p.Id,
                Name = p.Name,
                Description = p.Description,
                Price = p.Price,
                IsAvailable = p.Availability > 0
            }));
        }
Exemplo n.º 3
0
        public async Task <IEnumerable <ApiProduct> > Get(CancellationToken cancellationToken)
        {
            IEnumerable <Product> allProducts = await _catalogService.GetAllProducts();

            _logger.LogInformation("Start long process...");

            //for (var i = 0; i < 10; i++)
            //{
            cancellationToken.ThrowIfCancellationRequested();
            //	// slow non-cancellable work
            await Task.Delay(10_000);

            //}

            _logger.LogInformation("Finished long process...");

            return(allProducts.Select(p => new ApiProduct
            {
                Id = p.Id,
                Name = p.Name,
                Description = p.Description,
                Price = p.Price,
                IsAvailable = p.Availability > 0
            }));
        }
        public async Task <IEnumerable <APIProduct> > Get()
        {
            IEnumerable <Product> allProducts = await productCatalogService.GetAllProducts();

            return(allProducts.Select(p => new APIProduct
            {
                Id = p.Id,
                Name = p.Name
            }));
        }
        public async Task <IEnumerable <ApiProduct> > Get()
        {
            var products = await _catalogService.GetAllProducts().ConfigureAwait(false);

            return(products.Select(p => new ApiProduct
            {
                Id = p.Id,
                Name = p.Name,
                Description = p.Description,
                IsAvailable = p.Availability > 0,
                Price = p.Price
            }));
        }
Exemplo n.º 6
0
        public async Task <IEnumerable <ProductModel> > Get()
        {
            try
            {
                var products = await productCatalogService.GetAllProducts();

                return(products.Select(t => new ProductModel {
                    Id = t.Id, Description = t.Description, Name = t.Name, Price = t.Price, IsAvailability = t.Availability > 0
                }));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 7
0
        public async Task <IEnumerable <ApiProduct> > Get()
        {
            IEnumerable <Product> allProducts = await _catalogService.GetAllProducts();

            return(allProducts.Select(p => new ApiProduct
            {
                Id = p.Id,
                Name = p.Name,
                Description = p.Description,
                Price = p.Price
                        // IsAvailable = p.Availability > 0
            }));

            // return new[] { new ApiProduct() { Id = Guid.NewGuid(), Description = "Fake" } };
        }
Exemplo n.º 8
0
        public async Task <IEnumerable <ProductDto> > Get()
        {
            try
            {
                var products = await _productCatalogService.GetAllProducts();

                return(products.Select(product => new ProductDto()
                {
                    Id = product.Id,
                    Name = product.Name,
                    Description = product.Description,
                    IsAvailable = product.Availability > 0,
                    Price = product.Price
                }).ToList());
            }
            catch (Exception error)
            {
                throw error;
            }
        }
Exemplo n.º 9
0
        public async Task <IEnumerable <ProductViewModel> > Get()
        {
            try
            {
                var result = await _catalogService.GetAllProducts();

                return(result.Select(x => new ProductViewModel
                {
                    Description = x.Description,
                    Id = x.Id,
                    Name = x.Name,
                    Price = x.Price
                }));
            }
            catch (Exception ex)
            {
                string er = ex.ToString();
            }
            return(null);
        }
        public async Task <IEnumerable <ApiProduct> > Get()
        {
            try
            {
                IEnumerable <Product> allProducts = await _productCatalogService.GetAllProducts();

                return(allProducts.Select(product => new ApiProduct
                {
                    Id = product.Id,
                    Name = product.Name,
                    Description = product.Description,
                    Price = product.Price,
                    IsAvailable = product.Availability > 0
                }));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        public async Task <IEnumerable <ApiProduct> > Get()
        {
            try
            {
                var v = _someRepo.GetSomething();

                IEnumerable <Product> allProducts = await _catalogService.GetAllProducts();

                return(allProducts.Select(p => new ApiProduct
                {
                    Id = p.Id,
                    Name = p.Name,
                    Description = p.Description,
                    Price = p.Price,
                    IsAvailable = p.Availability > 0
                }));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public async Task <IEnumerable <ApiProduct> > Get()
        {
            IEnumerable <Product> allProducts = new List <Product>();

            try
            {
                allProducts = await _catalogService.GetAllProducts();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(allProducts.Select(p => new ApiProduct
            {
                Id = p.Id,
                Name = p.Name,
                Description = p.Description,
                Price = p.Price,
                IsAvailable = p.Availability > 0
            }));
        }
Exemplo n.º 14
0
 public async Task <IEnumerable <ProductDTO> > Get()
 {
     return(Mapper.Map <IEnumerable <Product>, IEnumerable <ProductDTO> >(await _catalogService.GetAllProducts()));
     //return new[] {new ProductDTO{Id = Guid.NewGuid(), Description = "fake"}};
 }
 public async Task <IEnumerable <ApiProduct> > Get()
 {
     return((await _catalogService.GetAllProducts()).Select(_mapper.Map <ApiProduct>));
 }
        public async Task <IEnumerable <Product> > Get()
        {
            var products = await _service.GetAllProducts();

            return(products.Select(p => new Product(p)));
        }