public List <Product> GetAllProducts() { List <Product> products = new List <Product>(); ProductsDAO dao = new ProductsDAO(); products = dao.GetAllProducts(); return(products); }
public IActionResult Index() { //HardCodedSampleDataRepo hardCodedSampleDataRepo = new HardCodedSampleDataRepo(); ProductsDAO products = new ProductsDAO(); return(View(products.GetAllProducts())); }
public IActionResult Index() { //HardCodedSampleDataRepository hardCodedSampleDataRepository = new HardCodedSampleDataRepository(); //return View(hardCodedSampleDataRepository.GetAllProducts()); ProductsDAO products = new ProductsDAO(); return(View(products.GetAllProducts())); }
private void LoadOtherProducts(int productId) { ProductsDAO productsDAO = new ProductsDAO(); ProductImagesDAO productImagesDAO = new ProductImagesDAO(); List <Product> allProductsList = productsDAO.GetAllProducts(); List <ProductImage> productImageList = productImagesDAO.GetAllProductImages(); List <Product> productsList = new List <Product>(); //Random 4 products for (int i = 0; i < Int32.MaxValue; i++) { Random random = new Random(); int randomNumber = random.Next(0, allProductsList.Count); Product product = allProductsList[randomNumber]; if ((!productsList.Contains(product)) && (product.id != productId)) { productsList.Add(product); } if (productsList.Count == 4) { break; } } ProductImage productImage = productImagesDAO.GetAllProductImages() .FindAll(pi => pi.productId.Equals(productsList[0].id)) .FirstOrDefault(); //P1 LoadProductInfo(hlOtherProduct1, imgOtherProduct1, productsList[0], productImage, lblPriceOtherProduct1, hlOtherProductZoom1, hlBuyOtherProduct1); productImage = productImagesDAO.GetAllProductImages() .FindAll(pi => pi.productId.Equals(productsList[1].id)) .FirstOrDefault(); //P2 LoadProductInfo(hlOtherProduct2, imgOtherProduct2, productsList[1], productImage, lblPriceOtherProduct2, hlOtherProductZoom2, hlBuyOtherProduct2); productImage = productImagesDAO.GetAllProductImages() .FindAll(pi => pi.productId.Equals(productsList[2].id)) .FirstOrDefault(); //P3 LoadProductInfo(hlOtherProduct3, imgOtherProduct3, productsList[2], productImage, lblPriceOtherProduct3, hlOtherProductZoom3, hlBuyOtherProduct3); productImage = productImagesDAO.GetAllProductImages() .FindAll(pi => pi.productId.Equals(productsList[3].id)) .FirstOrDefault(); //P4 LoadProductInfo(hlOtherProduct4, imgOtherProduct4, productsList[3], productImage, lblPriceOtherProduct4, hlOtherProductZoom4, hlBuyOtherProduct4); }
public IEnumerable <ProductModelDTO> Index() { List <ProductModel> products = repository.GetAllProducts(); //List<ProductModelDTO> productDTOs = new List<ProductModelDTO>(); //foreach(var item in products) //{ // productDTOs.Add(new ProductModelDTO(item)); //} IEnumerable <ProductModelDTO> prodDTOs = from p in products select new ProductModelDTO(p); return(prodDTOs); }
private void LoadMainProducts(int order, int productypeId = 0) { CategoriesDAO categoriesDAO = new CategoriesDAO(); List <Category> allCategoriesList = categoriesDAO.GetAllCategories(); Category manCategory = allCategoriesList.Find(c => c.name.ToUpper().Equals("MUJER")); ProductTypesDAO productTypesDAO = new ProductTypesDAO(); List <ProductType> productTypesList = productTypesDAO.GetAllProductTypes(); productTypesList = productTypesList.FindAll(pt => pt.categoryId.Equals(manCategory.id)).ToList(); ulProductTypesMan.Controls.Clear(); HtmlGenericControl liAll = new HtmlGenericControl("li"); HtmlGenericControl ianchorAll = new HtmlGenericControl("a"); liAll = new HtmlGenericControl("li"); ianchorAll = new HtmlGenericControl("a"); ianchorAll.Attributes.Add("href", "?productTypeId=-1#main"); ianchorAll.Attributes.Add("class", "active"); ianchorAll.InnerText = "Todas"; liAll.Controls.Add(ianchorAll); ulProductTypesMan.Controls.Add(liAll); foreach (ProductType productType in productTypesList) { HtmlGenericControl li = new HtmlGenericControl("li"); HtmlGenericControl ianchor = new HtmlGenericControl("a"); li = new HtmlGenericControl("li"); ianchor = new HtmlGenericControl("a"); ianchor.Attributes.Add("href", "?productTypeId=" + productType.id + "#main"); ianchor.Attributes.Add("class", "active"); ianchor.InnerText = productType.name; li.Controls.Add(ianchor); ulProductTypesMan.Controls.Add(li); } ProductsDAO productsDAO = new ProductsDAO(); ProductImagesDAO productImagesDAO = new ProductImagesDAO(); List <Product> allProductsList = productsDAO.GetAllProducts(); List <ProductImage> productImageList = productImagesDAO.GetAllProductImages(); List <Product> productsList = allProductsList.Where(p => productTypesList.Any(pl => pl.id.Equals(p.productTypeId))).ToList(); if (productypeId > 0) { productsList = allProductsList.FindAll(p => p.productTypeId.Equals(productypeId)); } //default order productsList = productsList.OrderBy(p => p.name).ToList(); switch (order) { //NOMBRE (A -Z) case 0: productsList = productsList.OrderBy(p => p.name).ToList(); break; //NOMBRE (Z -A) case 1: productsList = productsList.OrderByDescending(p => p.name).ToList(); break; //MENOR PRECIO case 2: productsList = productsList.OrderBy(p => Double.Parse(p.price)).ToList(); break; //MAYOR PRECIO case 3: productsList = productsList.OrderByDescending(p => Double.Parse(p.price)).ToList(); break; default: productsList = productsList.OrderBy(p => p.name).ToList(); break; } pnlProducts.Controls.Clear(); if (productsList.Count > 0) { foreach (Product product in productsList) { //P1 ProductImage productImage = productImagesDAO.GetAllProductImages() .FindAll(pi => pi.productId.Equals(product.id)).FirstOrDefault(); string url = "http://*****:*****@"<div class=""col-xs-12 col-sm-4""> <div class=""product-display product-description""> <figure class=""product-image""> <img id=""imgProduct1"" src=""" + ImageSrc + @""" alt=""image"" /> <div class=""overlay""> <div class=""product-view-block""> <div class=""product-view clearfix""> <a id=""hlProductZoom1"" href=""" + ImageSrc + @""" class=""zoom icon_zoom-in_alt single_image""></a> </div> <a id=""hlBuyProduct1"" href=""/Products.aspx?productId=" + product.id + @"#main"" class=""btn add-cart"">COMPRAR</a> </div> </div> </figure> <div class=""about-product""> <h4><a id=""hlProduct1"" href=""/Products.aspx?productId=" + product.id + @"#main"" class=""item-name"">" + product.name + @"</a></h4> <span class=""price""> <span id=""lblPrice1"">$ " + product.price + @"</span></span> </div> </div> </div>"; HtmlGenericControl div = new HtmlGenericControl("div"); div.InnerHtml = productDescription; pnlProducts.Controls.Add(div); } ////P8 //LoadProductInfo(hlProduct8, imgProduct8, productsList[7], productImage, lblPrice8, hlProductZoom8, hlBuyProduct8); //productImage = productImagesDAO.GetAllProductImages() // .FindAll(pi => pi.productId.Equals(productsList[8].id)) // .FirstOrDefault(); ////P9 //LoadProductInfo(hlProduct9, imgProduct9, productsList[8], productImage, lblPrice9, hlProductZoom9, hlBuyProduct9); } }
public ActionResult <IEnumerable <ProductModel> > Index() // IEnumerable is better than list and // but also we can use List { return(repository.GetAllProducts()); }
private void LoadProducts() { ProductsDAO productsDAO = new ProductsDAO(); ProductImagesDAO productImagesDAO = new ProductImagesDAO(); List <Product> productsList = productsDAO.GetAllProducts(); List <ProductImage> productImageList = productImagesDAO.GetAllProductImages(); ProductImage productImage = productImagesDAO.GetAllProductImages() .FindAll(pi => pi.productId.Equals(productsList[0].id)) .FirstOrDefault(); //P1 LoadProductInfo(hlProduct1, imgProduct1, productsList[0], productImage, lblPrice1, hlProductZoom1, hlBuyProduct1); productImage = productImagesDAO.GetAllProductImages() .FindAll(pi => pi.productId.Equals(productsList[1].id)) .FirstOrDefault(); //P2 LoadProductInfo(hlProduct2, imgProduct2, productsList[1], productImage, lblPrice2, hlProductZoom2, hlBuyProduct2); productImage = productImagesDAO.GetAllProductImages() .FindAll(pi => pi.productId.Equals(productsList[2].id)) .FirstOrDefault(); //P3 LoadProductInfo(hlProduct3, imgProduct3, productsList[2], productImage, lblPrice3, hlProductZoom3, hlBuyProduct3); productImage = productImagesDAO.GetAllProductImages() .FindAll(pi => pi.productId.Equals(productsList[3].id)) .FirstOrDefault(); //P4 LoadProductInfo(hlProduct4, imgProduct4, productsList[3], productImage, lblPrice4, hlProductZoom4, hlBuyProduct4); productImage = productImagesDAO.GetAllProductImages() .FindAll(pi => pi.productId.Equals(productsList[4].id)) .FirstOrDefault(); //P5 LoadProductInfo(hlProduct5, imgProduct5, productsList[4], productImage, lblPrice5, hlProductZoom5, hlBuyProduct5); productImage = productImagesDAO.GetAllProductImages() .FindAll(pi => pi.productId.Equals(productsList[5].id)) .FirstOrDefault(); //P6 LoadProductInfo(hlProduct6, imgProduct6, productsList[5], productImage, lblPrice6, hlProductZoom6, hlBuyProduct6); productImage = productImagesDAO.GetAllProductImages() .FindAll(pi => pi.productId.Equals(productsList[6].id)) .FirstOrDefault(); //P7 LoadProductInfo(hlProduct7, imgProduct7, productsList[6], productImage, lblPrice7, hlProductZoom7, hlBuyProduct7); productImage = productImagesDAO.GetAllProductImages() .FindAll(pi => pi.productId.Equals(productsList[7].id)) .FirstOrDefault(); //P7 LoadProductInfo(hlProduct8, imgProduct8, productsList[7], productImage, lblPrice8, hlProductZoom8, hlBuyProduct8); }
public ActionResult <IEnumerable <ProductModel> > Index() { //HardCodedSampleDataRepository hardCodedSampleDataRepository = new HardCodedSampleDataRepository(); return(productsDAO.GetAllProducts()); }