public ActionResult GetproductsOfOneCategory(int id) { List <Product> ProductList = context.Product.Where(P => P.CategoryObj.CategoryId == id).ToList(); List <ProductWithImag> MyProductWithImages = new List <ProductWithImag>(); ProductWithImag ProductWithImagObejct; foreach (var item in ProductList) { ProductWithImagObejct = new ProductWithImag(); ProductWithImagObejct.ProductId = item.ProductId; ProductWithImagObejct.productName = item.productName; ProductWithImagObejct.Price = item.Price; ProductWithImagObejct.Description = item.Description; ProductWithImagObejct.Quantity = item.Quantity; ProductWithImagObejct.ProductDetails = item.ProductDetails; if (item.IamgesList.Count != 0) { ProductWithImagObejct.ImagesUrl = item.IamgesList.ElementAt(0).ImagesUrl; } else { ProductWithImagObejct.ImagesUrl = @"\Content\images\PoductImages\Dummy.jpg"; } MyProductWithImages.Add(ProductWithImagObejct); } return(View("GetproductsOfOneCategory", MyProductWithImages)); }
public ActionResult GetProducts(int CatId) { List <ProductWithImag> MyProductWithImages = new List <ProductWithImag>(); ProductWithImag ProductWithImagObejct; category slectedCategory = context.Category.FirstOrDefault(cat => cat.CategoryId == CatId); List <Product> ProductList = slectedCategory.ProductLis.ToList(); foreach (var item in ProductList) { ProductWithImagObejct = new ProductWithImag(); ProductWithImagObejct.ProductId = item.ProductId; ProductWithImagObejct.productName = item.productName; ProductWithImagObejct.Price = item.Price; ProductWithImagObejct.Description = item.Description; ProductWithImagObejct.Quantity = item.Quantity; ProductWithImagObejct.ProductDetails = item.ProductDetails; if (item.IamgesList.Count != 0) { ProductWithImagObejct.ImagesUrl = item.IamgesList.ElementAt(0).ImagesUrl; } else { ProductWithImagObejct.ImagesUrl = @"\Content\images\PoductImages\Dummy.jpg"; } MyProductWithImages.Add(ProductWithImagObejct); } return(PartialView("_PartialProductsBlock", MyProductWithImages)); }
public ActionResult Index() { List <ProductWithImag> MyProductWithImages = new List <ProductWithImag>(); ProductWithImag ProductWithImagObejct; //List<string> Images = new List<string>(); //Get list of all category List <category> CategoryList = context.Category.ToList(); //Get first Category List <Product> data = new List <Product>(); category FirstCategory = context.Category.FirstOrDefault(); if (FirstCategory != null) { data = FirstCategory.ProductLis.ToList(); } //Get First Slider SliderImage FirstSlider = context.SliderImage.FirstOrDefault(); //List<Product> data = context.Product.ToList(); //fill List of ProductWithImages foreach (var item in data) { ProductWithImagObejct = new ProductWithImag(); ProductWithImagObejct.ProductId = item.ProductId; ProductWithImagObejct.productName = item.productName; ProductWithImagObejct.Price = item.Price; ProductWithImagObejct.Description = item.Description; ProductWithImagObejct.Quantity = item.Quantity; ProductWithImagObejct.ProductDetails = item.ProductDetails; if (item.IamgesList.Count != 0) { ProductWithImagObejct.ImagesUrl = item.IamgesList.ElementAt(0).ImagesUrl; } else { ProductWithImagObejct.ImagesUrl = @"\Content\images\PoductImages\Dummy.jpg"; } MyProductWithImages.Add(ProductWithImagObejct); } CatProductWithImageSliderViewModel ViewObj = new CatProductWithImageSliderViewModel(); ViewObj.ListOfCategory = CategoryList; ViewObj.ProductWithImagList = MyProductWithImages; ViewObj.SliderImageObg = FirstSlider; //ViewData["firstIamge"] = Images;//list of URL of ALl Image of product // return View(MyProductWithImages); return(View(ViewObj)); }
// GET: listitemproduct public ActionResult Index() { List <ProductWithImag> MyProductWithImages = new List <ProductWithImag>(); ProductWithImag ProductWithImagObejct; List <string> Images = new List <string>(); List <Product> data = context.Product.ToList(); foreach (var item in data) { ProductWithImagObejct = new ProductWithImag(); ProductWithImagObejct.ProductId = item.ProductId; ProductWithImagObejct.productName = item.productName; ProductWithImagObejct.Price = item.Price; ProductWithImagObejct.Description = item.Description; ProductWithImagObejct.Quantity = item.Quantity; ProductWithImagObejct.ProductDetails = item.ProductDetails; ProductWithImagObejct.ImagesUrl = item.IamgesList.ElementAt(0).ImagesUrl; MyProductWithImages.Add(ProductWithImagObejct); } return(View(MyProductWithImages)); }