Exemple #1
0
        public IActionResult Index()
        {
            var allProducts = _productsService.GetAll();

            var productsModels = allProducts
                                 .Select(p => new ProductsDetailsModel
            {
                IdProduct          = p.IdProduct,
                ProductName        = p.ProductName ?? "No First Name Provided",
                ProductNumber      = p.ProductNumber,
                ProductDescription = p.ProductDescription,
                QuantityUnit       = p.QuantityUnit,
                Discount           = p.Discount,
                CategoryName       = new List <SelectListItem>()
                {
                    new SelectListItem(p.Categoriess.NameCategories, "1")
                }
            }).ToList();

            var model = new ProductsIndexModel
            {
                Products = productsModels
            };


            return(View(model));
        }
Exemple #2
0
        // GET: Products
        public ActionResult Index()
        {
            var pim  = new ProductsIndexModel();
            var repo = new ProductsRepository();

            pim.Categories = repo.AllCategories().ToList();
            pim.Products   = repo.AllProducts().ToList();
            return(View(pim));
        }
Exemple #3
0
        public async Task <IActionResult> Index(double?PriceLow, double?PriceHigh, string Name, string Description, int BrandId = 0, int CategoryId = 0)
        {
            var authenticated = false;

            try
            {
                var authentication = await HttpContext.AuthenticateAsync();

                authenticated = authentication.Succeeded;
            }
            catch
            {
            }

            var products = await _context.GetAllActive();

            if (BrandId != 0)
            {
                products = products.Where(p => p.BrandId == BrandId).ToList();
            }
            if (CategoryId != 0)
            {
                products = products.Where(p => p.CategoryId == CategoryId).ToList();
            }

            if (!String.IsNullOrEmpty(Name))
            {
                products = products.Where(p => p.Name.ToLower().Contains(Name.ToLower())).ToList();
            }
            if (!String.IsNullOrEmpty(Description))
            {
                products = products.Where(p => p.Description.Contains(Description)).ToList();
            }

            var productsWithPriceStock = new List <ProductsPriceStockModel>();

            var client = GetHttpClient("StandardRequest");

            client.DefaultRequestHeaders.Accept.ParseAdd("application/json");

            var response = await client.GetAsync("https://localhost:44385/stock/ProductStocks");

            if (response.IsSuccessStatusCode)
            {
                var objectResult = await response.Content.ReadAsAsync <List <MultipleStockDTO> >();

                foreach (var t in products)
                {
                    int?stock = null;
                    if (authenticated)
                    {
                        stock = objectResult.FirstOrDefault(or => or.ProductStock.ProductId == t.Id).ProductStock.Stock;
                    }
                    productsWithPriceStock.Add(new ProductsPriceStockModel
                    {
                        Product = t,
                        Price   = objectResult.FirstOrDefault(or => or.ProductStock.ProductId == t.Id).Price.ProductPrice,
                        Stock   = stock
                    });
                }
            }
            else
            {
                productsWithPriceStock.AddRange(products.Select(p => new ProductsPriceStockModel {
                    Product = p, Price = null, Stock = null
                }));
            }

            var productIndex = new ProductsIndexModel
            {
                Name        = Name ?? "",
                Description = Description ?? "",
                Products    = productsWithPriceStock,
                BrandId     = BrandId,
                CategoryId  = CategoryId
            };

            var selectListBrands = new List <Brand> {
                new Brand {
                    Id = 0, Name = "All Brands"
                }
            };

            selectListBrands.AddRange(await _context.GetBrandsAsync());
            var selectListCategories = new List <Category> {
                new Category {
                    Id = 0, Name = "All Categories"
                }
            };

            selectListCategories.AddRange(await _context.GetCategoriesAsync());

            ViewData["BrandList"]    = new SelectList(selectListBrands, "Id", "Name");
            ViewData["CategoryList"] = new SelectList(selectListCategories, "Id", "Name");

            return(View(productIndex));
        }