public IActionResult Search(string search, int page = 1) { List <Museums> list = new List <Museums>(); if (search != null) { list = museumRepository.Search(search); } else { list = museumRepository.GetMuseums(); } List <MuseumVM> model = new List <MuseumVM>(); const int PageSize = 12; var count = list.Count(); if (page == 1) { list = list.Skip(0).Take(PageSize).ToList(); } else { list = list.Skip((page - 1) * PageSize).Take(PageSize).ToList(); } if (count <= PageSize) { ViewBag.MaxPage = 1; } else { if (count % PageSize == 0) { ViewBag.MaxPage = (count / PageSize); } else { ViewBag.MaxPage = (count / PageSize) + 1; } } ViewBag.Page = page; ViewBag.NextPage = page + 1; foreach (Museums x in list) { MuseumVM vm = new MuseumVM(); vm.Id = x.Id; vm.Address = x.Address; vm.Name = x.Name; vm.Image = imageRepository.GetMuseumImage(x.Id); if (vm.Image != null) { vm.ImageId = vm.Image.Id; } model.Add(vm); } return(View("Index", model)); }
public IActionResult Search(string search) { List <Museums> model = new List <Museums>(); if (search != null) { model = museumRepository.Search(search); } else { model = museumRepository.GetMuseums(); } return(View("Index", model)); }