//SEARCH READ (CATEGORY) public IActionResult searchReadCategory(string name) { List <Kategorije> kategorije; ViewBag.name = name; if (name != null) { kategorije = _kategorijeServices.searchReadCategory(name); } else { kategorije = _kategorijeServices.Read(); } var viewmodel = new AdminViewModel { kategorije = kategorije }; return(View(viewmodel)); }
public IActionResult Courses(string naziv, string search, int?level, int?page, string schoolID) { // search ViewBag.search = search; ViewBag.level = level; if (schoolID != null) { ViewBag.school = _schoolServices.Find(schoolID); } else { ViewBag.school = null; } List <Kursevi> listKurseva; List <Kategorije> listKategorija; string kategorijaID = null; if (naziv != null) { var kategorija = _kategorijeServices.FindByName(naziv); if (kategorija == null) { return(NotFound()); } kategorijaID = kategorija.kategorijaID; } if (page == null) { page = 1; } int pageSize = 9; ViewBag.page = page; if (level == null) { level = 0; // svi nivoi } int courseCount; (listKurseva, courseCount) = _kurseviServices.GetCourses(kategorijaID, search, (int)level, (int)page, pageSize, schoolID); double maxPages = (double)courseCount / pageSize; ViewBag.maxPages = (int)Math.Ceiling(maxPages); ViewBag.total = courseCount; listKategorija = _kategorijeServices.Read(); var kursevi = new List <DetailsForCourseViewModel>(); foreach (var item in listKurseva) { // skracivanje opisa kursa if (item.detaljikursa.Length > 50) { item.detaljikursa = item.detaljikursa.Substring(0, 50) + "..."; } if (item.imekursa.Length > 46) { item.imekursa = item.imekursa.Substring(0, 44) + "..."; } kursevi.Add(new DetailsForCourseViewModel() { kurs = item, nivo = _kurseviServices.getLevel(item.nivoKursa) }); } var viewmodel = new KursKategorijaViewModel { kategorijes = listKategorija, kursevis = kursevi, }; ViewBag.kursevi = kursevi; return(View(viewmodel)); }