public void Valid_IndexReturnsViewResult() { var mockDbContext = new Mock <ApplicationDbContext>(); BruidController controller = initDB(mockDbContext); FilterSelectie filterSelectie = new FilterSelectie() { Categorie = 1, MinPrijs = 1000, MaxPrijs = 6000 }; var result = controller.Index(filterSelectie); var viewResult = Assert.IsType <ViewResult>(result); }
//functie om producten te sorteren private List <Product> sorteren(FilterSelectie f, List <Product> p) { switch (f.SortingOptie) { case "PrijsLH": return(p.OrderByDescending(x => x.Prijs).ToList()); case "PrijsHL": return(p.OrderBy(x => x.Prijs).ToList()); case "MerkAZ": return(p.OrderBy(x => x.Merk.Naam).ToList()); case "MerkZA": return(p.OrderByDescending(x => x.Merk.Naam).ToList()); } return(p); }
//categorie pagina met filters public IActionResult Categorie(FilterSelectie filterSelectie) { var producten = _context.Product.Include(x => x.Merk).Include(x => x.Product_X_Kenmerk).ThenInclude(x => x.Kenmerk).ToList(); _filter.MaxPrijs = producten.Max(x => x.Prijs); //elke if controleert of de filter was geselecteerd if (filterSelectie.Categorie != null && filterSelectie.Categorie != 0) { producten = producten.Where(x => x.Categorie.Id == filterSelectie.Categorie).ToList(); } if (filterSelectie.MinPrijs != null && filterSelectie.MaxPrijs != null) { producten = producten.Where(x => x.Prijs >= filterSelectie.MinPrijs && x.Prijs <= filterSelectie.MaxPrijs).ToList(); } if (filterSelectie.Merken.Count() != 0) { producten = producten.Where(x => filterSelectie.Merken.Contains(x.Merk.Id)).ToList(); } if (filterSelectie.Kenmerken.Count != 0) { producten = producten.FindAll(x => x.Product_X_Kenmerk.Any(y => filterSelectie.Kenmerken.Contains(y.KenmerkId))); } //bool om te controleren of er een kleur selected is filterSelectie.Kleurselected = filterSelectie.Kenmerken.Intersect(_context.Kenmerk.Where(x => x.Type.Equals("Kleur")).Select(x => x.Id)).Any(); /*sorteren*/ producten = sorteren(filterSelectie, producten); /*paginanummering*/ paginanummering(filterSelectie, producten); List <Product> limitedProducts = producten.Skip((filterSelectie.Paginanummer - 1) * filterSelectie.AantalTonen).Take(filterSelectie.AantalTonen).ToList(); return(View(new ProductFilter(_filter, filterSelectie, limitedProducts))); }
//functie die de waardes voor paginanummering regelen private void paginanummering(FilterSelectie f, List <Product> p) { ViewBag.aantalPagina = Math.Ceiling(Double.Parse(p.Count + "") / f.AantalTonen); ViewBag.huidigePagina = f.Paginanummer; ViewBag.aantalTonen = f.AantalTonen; }
//index pagina waar er 6 producten worden getoond public IActionResult Index(FilterSelectie filterSelectie) { var producten = _context.Product.Include(x => x.Merk).Include(x => x.Product_X_Kenmerk).ThenInclude(x => x.Kenmerk).Take(6).ToList(); return(View(new ProductFilter(_filter, filterSelectie, producten))); }