public ActionResult Search(string search, string sort) { var model = new SkorIndexViewModel(); model.Search = search; if (!string.IsNullOrEmpty(search)) { using (var db = new SkorModelDB()) { model.SkorList.AddRange(db.SkorTable .Select(x => new SkorIndexViewModel.SkorListViewModel { ID = x.SkorId, Name = x.Name, Model = x.Model, Size = x.Size, Color = x.Color, Price = x.Price, Description = x.Description, CategoryId = x.CategoryId })); model.SkorList = model.SkorList.Where(x => x.Name.ToUpper().Contains(search.ToUpper())).ToList(); model = Sort(model, sort); return(View("Search", model)); } } return(View("Search", model)); }
public SkorIndexViewModel Sort(SkorIndexViewModel model, string sort) { if (string.IsNullOrEmpty(sort)) { sort = "SkorNameAsc"; } model.SortOrder = sort == "SkorNameDesc" ? "SkorNameAsc" : "SkorNameDesc"; switch (sort) { case "SkorNameAsc": model.SkorList = model.SkorList.OrderBy(x => x.Name).ToList(); break; case "SkorNameDesc": model.SkorList = model.SkorList.OrderByDescending(x => x.Name).ToList(); break; } return(model); }
public ActionResult AllSkor() { var model = new SkorIndexViewModel(); using (var db = new SkorModelDB()) { model.SkorList.AddRange(db.SkorTable.Select(x => new SkorIndexViewModel.SkorListViewModel { ID = x.SkorId, Name = x.Name, Model = x.Model, Color = x.Color, Size = x.Size, Price = x.Price, Description = x.Description, CategoryId = x.CategoryId })); return(View(model)); } }
public ActionResult Index(int id, string sort) { var model = new SkorIndexViewModel(); using (var db = new SkorModelDB()) { model.CategoryName = string.Join("", db.CategoriesTable.Where(x => x.CategoryId == id).Select(x => x.CategoryName)); model.CategoryId = id; model.SkorList.AddRange(db.SkorTable.Select(p => new SkorIndexViewModel.SkorListViewModel { ID = p.SkorId, Name = p.Name, Model = p.Model, Color = p.Color, Size = p.Size, Price = p.Price, Description = p.Description, CategoryId = p.CategoryId }).Where(p => p.CategoryId == id)); model = Sort(model, sort); return(View(model)); } }