public async Task <IActionResult> Edit(int id, [Bind("MainCategoryViewModelId,MainCategoryName")] MainCategoryViewModel mainCategoryViewModel) { if (id != mainCategoryViewModel.MainCategoryViewModelId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(mainCategoryViewModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MainCategoryViewModelExists(mainCategoryViewModel.MainCategoryViewModelId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(mainCategoryViewModel)); }
public async Task <IActionResult> Create([Bind("MainCategoryViewModelId,MainCategoryName")] MainCategoryViewModel mainCategoryViewModel) { if (ModelState.IsValid) { _context.Add(mainCategoryViewModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(mainCategoryViewModel)); }
//Generating ProductList by category ID public ActionResult Categories(int id) { ShowSidebar(); var categorie = db.MainCategories.SingleOrDefault(c => c.ID == id); if (categorie == null) { return(HttpNotFound()); } var ProductList = new MainCategoryViewModel() { Category = categorie, Products = db.Products.Where(c => c.MainCategoryID.Equals(id)).ToList().AsEnumerable() }; return(View(ProductList)); }
//pagination public ActionResult Pagination(int categoryId, int pageId) { ShowSidebar(); //create a cookie HttpCookie pageCookie = new HttpCookie("pageCookie"); //add key-values in the cookie pageCookie.Values.Add("pageId", pageId.ToString()); pageCookie.Expires = DateTime.Now.AddMinutes(30); //write the cookie to the client Response.Cookies.Add(pageCookie); ViewBag.PageId = pageId; var categorie = db.MainCategories.SingleOrDefault(c => c.ID == categoryId); if (categorie == null) { return(HttpNotFound()); } int items = 12; int skipPages = 0; int maxProducts = db.Products.Where(c => c.MainCategoryID.Equals(categoryId)).Count(); ViewBag.maxPages = maxProducts / items; if (pageId > 1) { skipPages = items * pageId; } var ProductList = new MainCategoryViewModel() { Category = categorie, Products = db.Products.Where(c => c.MainCategoryID.Equals(categoryId)).ToList().AsEnumerable().Skip(skipPages).Take(items) }; return(View(ProductList)); }
public ActionResult Search(int selectedValue, string searchString) { if (String.IsNullOrEmpty(searchString)) { ViewBag.Message = "Er is geen zoekopdracht ingevoerd. Hier zijn al onze producten."; } var category = _context.MainCategories.FirstOrDefault(); int cid = selectedValue; var ProductList = new MainCategoryViewModel(); if (cid == 0) { ProductList = new MainCategoryViewModel() { Category = category, Products = _context.Products .Where(c => c.Name.Contains(searchString) || c.Description.Contains(searchString)) .ToList().AsEnumerable() }; } else { ProductList = new MainCategoryViewModel() { Category = category, Products = _context.Products .Where(c => (c.Name.Contains(searchString) || c.Description.Contains(searchString)) && c.MainCategoryID.Equals(cid)) .ToList().AsEnumerable() }; } if (ProductList.Products.ToList().Count == 0) { ViewBag.Message = "Geen overeenkomende zoekresultaten op: " + searchString; } return(View(ProductList)); }
public MainCategoryPage() { InitializeComponent(); BindingContext = viewModel = new MainCategoryViewModel(); }