public async Task <IActionResult> Edit(string id, [Bind("Id,Name,Price,Photo")] HomeProducts homeProducts) { if (id != homeProducts.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(homeProducts); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HomeProductsExists(homeProducts.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(homeProducts)); }
// Tag related End public async Task <IEnumerable <HomeProducts> > AllSearchProduct(SearchViewModel model) { var collection = await _context.Products.Select(a => new ProductHome { ProductName = a.ProductName, CityId = a.CityId, CategoryId = a.CategoryId, basePrice = a.BasePrice, productId = a.Id, startDate = a.StartDateTime, endDate = a.EndDateTime, Bid = a.Bids.AsQueryable().OrderByDescending(x => x.BidPrice).FirstOrDefault(), Image = a.Image.AsQueryable().FirstOrDefault() }).AsNoTracking().ToListAsync(); List <HomeProducts> result = new List <HomeProducts>(); // Console.WriteLine("Name"+model.searchName); // Console.WriteLine("Cat"+model.Category); // Console.WriteLine("City"+model.City); //Filtering And Lazy Explicit Loding foreach (var item in collection) { if (model.Category != null && item.CategoryId != model.Category) { continue; } if (model.City != null && item.CityId != model.City) { continue; } if (model.searchName != null && !item.ProductName.Contains(model.searchName)) { continue; } HomeProducts temp = new HomeProducts(); temp.productId = item.productId; temp.productName = item.ProductName; temp.basePrice = item.basePrice; if (item.Bid != null) { temp.bidderId = item.Bid.ApplicationUserId; temp.bidPrice = item.Bid.BidPrice; item.Bid = await _context.Bid.Include(x => x.ApplicationUser).SingleAsync(y => y.Id == item.Bid.Id); temp.bidderName = item.Bid.ApplicationUser.UserName; } temp.image = item.Image.ImgPath; temp.startDate = item.startDate; temp.endDate = item.endDate; result.Add(temp); } return((IEnumerable <HomeProducts>)result); }
public async Task <IActionResult> Create([Bind("Id,Name,Price,Photo")] HomeProducts homeProducts) { if (ModelState.IsValid) { _context.Add(homeProducts); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(homeProducts)); }
public ActionResult Index() { List <Product> Products = new Biz.ProductBiz().GetAll(); var GameApps = new Biz.GroupBiz().GetAll().Where(x => x.Type == AppStore.Models.TypeGroup.Game).SelectMany(p => p.Products).ToList(); var NewApps = Products.OrderByDescending(x => x.DateTime).Take(20).ToList(); HomeProducts result = new HomeProducts() { Games = GameApps, NewApps = NewApps, }; var Downloads = new Biz.DownloadBiz().GetAll(); var mostDownload = (from t in Downloads group t by t.Product.Id into g select new { ProductId = g.Key, Count = g.Count() }).OrderByDescending(x => x.Count) .Select(x => x.ProductId) .Take(20) .ToList(); result.MostDownloaded = Products.Where(x => mostDownload.Contains(x.Id)).ToList(); return(View(result)); }