public IActionResult Index() { ProductListViewModel result = new ProductListViewModel(); var products = _context.Products.Where(p => p.Status == true).ToList(); result.Category = new System.Collections.Generic.List <SelectListItem>(); ViewBag.categories = _context.Category.ToList(); foreach (var product in products) { HomeProductViewModel model = new HomeProductViewModel(); model.Product = product; model.AvgRating = GetAvgRatingProduct(product.Id); var images = _context.Image.Where(d => d.ProductId == product.Id); var mainImage = images.Where(c => c.Main == true); var secImage = images.Where(c => c.Main != true).Take(1); foreach (var mImage in mainImage) { model.MainImage = mImage.Name; } foreach (var sImage in secImage) { model.SecondImage = sImage.Name; } result.Product.Add(model); } return(View(result)); }
public ActionResult Details(int id) { Product product = postRepository.GetProductById(id); HomeProductViewModel model = new HomeProductViewModel() { Id = product.Id, Title = product.Title, Description = product.Description, Price = product.Price, images = product.Image }; return(View(model)); }
public IActionResult Products(string key) { ViewData["NavigationViewModel"] = GetNavigation(); HomeProductViewModel model = new HomeProductViewModel(); model.Products = _context.Products .Where(p => p.Name.Contains(key)) .ToList <Product>(); model.Key = key; return(View(model)); }
public async Task <IViewComponentResult> InvokeAsync() { var langId = await HttpContext.GetLanguage(db); HomeProductViewModel model = new HomeProductViewModel() { CategoryLanguages = await db.CategoryLanguages.Where(cl => cl.LanguageId == langId).Include(cl => cl.Category).ToListAsync(), SubcategoryLanguages = await db.SubcategoryLanguages.Where(sl => sl.LanguageId == langId).Include(sl => sl.Subcategory).ToListAsync() }; return(View(model)); }
public IActionResult Category(int category) { ViewData["NavigationViewModel"] = GetNavigation(); HomeProductViewModel model = new HomeProductViewModel(); model.Products = ( from p in _context.Products join c in _context.Categories on p.Category.CategoryID equals c.CategoryID where c.CategoryID == category select p ).ToList <Product>(); model.category = _context.Categories.Find(category); return(View("Products", model)); }
public IActionResult VendorProfile(string Id) { ViewBag.storeInfo = _context.Vendors.Find(Id); var review = _context.Reviews.Where(p => p.VendorId == Id).ToList(); ViewBag.AvgRating = GetAvgRating(review); ViewBag.TotalReview = review.Count(); var products = _context.Products.Where(p => p.VendorId == Id && p.Status == true).ToList(); var result = new HomeViewModel(); foreach (var product in products) { HomeProductViewModel model = new HomeProductViewModel(); model.Product.Id = product.Id; model.Product.Name = product.Name; model.AvgRating = GetAvgRatingProduct(product.Id); var images = _context.Image.Where(d => d.ProductId == product.Id); var mainImage = images.Where(c => c.Main == true); var secImage = images.Where(c => c.Main != true).Take(1); foreach (var mImage in mainImage) { model.MainImage = mImage.Name; } foreach (var sImage in secImage) { model.SecondImage = sImage.Name; } model.Product.Price = product.Price; result.Products.Add(model); } result.Combo = new List <ComboViewModel>(); result.Combo = GetVendorCombo(Id); //var empty = result.Combo.Where(p => p.ComboId == 0); //if (empty != null) //{ // result.Combo.Remove(empty.FirstOrDefault()); //} return(View(result)); }
public IActionResult Search() { try { string keyword = Request.Query["keyword"]; var result = new ProductListViewModel(); var listProducts = _context.Products.Where(p => p.Name.Contains(keyword) && p.Status).ToList(); result.Category = new System.Collections.Generic.List <SelectListItem>(); ViewBag.categories = _context.Category.ToList(); foreach (var product in listProducts) { HomeProductViewModel model = new HomeProductViewModel(); model.Product.Id = product.Id; model.Product.Name = product.Name; model.AvgRating = GetAvgRatingProduct(product.Id); model.Product.CategoryId = product.CategoryId; var images = _context.Image.Where(d => d.ProductId == product.Id); var mainImage = images.Where(c => c.Main == true); var secImage = images.Where(c => c.Main != true).Take(1); foreach (var mImage in mainImage) { model.MainImage = mImage.Name; } foreach (var sImage in secImage) { model.SecondImage = sImage.Name; } model.Product.Price = product.Price; result.Product.Add(model); } return(View("Search", result)); } catch (Exception e) { throw; } }
public ActionResult Index() { // try // { var result = new HomeViewModel(); var topSelling = _context.TopSelling.OrderByDescending(p => p.Count).Take(8).ToList(); result.TopSelling = new List <HomeProductViewModel>(); foreach (var p in topSelling) { var product = _context.Products.Find(p.ProductId); HomeProductViewModel model = new HomeProductViewModel(); model.Product = product; model.AvgRating = GetAvgRatingProduct(product.Id); var images = _context.Image.Where(d => d.ProductId == product.Id); var mainImage = images.Where(c => c.Main == true); var secImage = images.Where(c => c.Main != true).Take(1); foreach (var mImage in mainImage) { model.MainImage = mImage.Name; } foreach (var sImage in secImage) { model.SecondImage = sImage.Name; } result.TopSelling.Add(model); } var products = _context.Products.Where(p => p.Status == true).OrderByDescending(p => p.Id).Take(8); result.Categories = _context.LifeStyleCategory.ToList(); foreach (var product in products) { HomeProductViewModel model = new HomeProductViewModel(); model.Product = product; model.AvgRating = GetAvgRatingProduct(product.Id); var images = _context.Image.Where(d => d.ProductId == product.Id); var mainImage = images.Where(c => c.Main == true); var secImage = images.Where(c => c.Main != true).Take(1); foreach (var mImage in mainImage) { model.MainImage = mImage.Name; } foreach (var sImage in secImage) { model.SecondImage = sImage.Name; } result.Products.Add(model); } //var Combos = _context.ComboRecommendation.Take(8); //foreach (var combo in Combos) //{ // HomeComboViewModel model = new HomeComboViewModel(); // model.Combo.Id = combo.Id; // model.Combo.Name = combo.Name; // var images = _context.ComboPhoto.Where(d => d.ComboId == combo.Id); // var mainImage = images.Where(c => c.Main == true); // var secImage = images.Where(c => c.Main != true).Take(1); // foreach (var mImage in mainImage) // { // model.MainImage = mImage.Name; // } // foreach (var sImage in secImage) // { // model.SecondImage = sImage.Name; // } // model.Combo.Price = combo.Price; // result.Combo.Add(model); //} return(View(result)); // } // catch(Exception e) //{ // throw; //} }
public ActionResult Product() { HomeProductViewModel productLines = _homeOperations.GetHomeProductViewModel(); return(View(productLines)); }