public IActionResult Index(IndexVM model) { model.Page = model.Page <= 0 ? 1 : model.Page; model.ItemsPerPage = model.ItemsPerPage <= 0 ? 10 : model.ItemsPerPage; ProductsRepository repo = new ProductsRepository(); Expression <Func <Product, bool> > filter = p => ( (model.Id == 0 || model.Id == p.Id) && (model.Price == "" || model.Price == null || p.CurrentPrice >= decimal.Parse(model.Price)) && (string.IsNullOrEmpty(model.Name) || p.Name.Contains(model.Name))); model.Items = repo.GetAll(filter, model.Page, model.ItemsPerPage); model.PagesCount = (int)Math.Ceiling((double)repo.Count(filter) / (double)model.ItemsPerPage); return(View(model)); }