//Index public ActionResult Index(IndexM model) { // Page and items per page numbers validation. if (model.Page <= 0) { model.Page = 1; } if (model.ItemsPerPage <= 0) { model.ItemsPerPage = 2; } ProjectsRepo projectRepo = new ProjectsRepo(); // Saving the filter for shown projects. Expression <Func <Project, bool> > filter = p => ((String.IsNullOrEmpty(model.Name)) || (p.Name.Contains(model.Name))) && ((String.IsNullOrEmpty(model.Description)) || (p.Description.Contains(model.Description))) && ((String.IsNullOrEmpty(model.Client)) || (p.Client.Contains(model.Client))); // Saving the filtered projects to the model. model.Items = projectRepo.GetAll(filter, model.Page, model.ItemsPerPage); // Saving the pages count to the model. model.PagesCount = (int)Math.Ceiling(projectRepo.Count() / (double)(model.ItemsPerPage)); return(View(model)); }
//Index public ActionResult Index(IndexM model) { // Page and items per page numbers validation. if (model.Page <= 0) { model.Page = 1; } if (model.ItemsPerPage <= 0) { model.ItemsPerPage = 2; } UsersRepo usersRepo = new UsersRepo(); // Saving the filter for shown users. Expression <Func <User, bool> > usersFilter = u => ((String.IsNullOrEmpty(model.Username)) || (u.Username.Contains(model.Username))) && ((String.IsNullOrEmpty(model.FirstName)) || (u.FirstName.Contains(model.FirstName))) && ((String.IsNullOrEmpty(model.LastName)) || (u.LastName.Contains(model.LastName))); // Saving the filtered users to the model. model.Items = usersRepo.GetAll(usersFilter, model.Page, model.ItemsPerPage); // Saving the pages count to the model. model.PagesCount = (int)Math.Ceiling( (usersRepo.Count(usersFilter)) / (double)(model.ItemsPerPage) ); return(View(model)); }