public IActionResult All(RigsAllInputModel input) { if (input.Page <= 0) { return(this.NotFound()); } var rigs = this.rigsService.GetAll <RigInListViewModel>(input); int rigsCount; if (!string.IsNullOrEmpty(input.Search)) { rigsCount = this.rigsService.GetSearchCount(input.Search); } else { rigsCount = this.rigsService.GetCount(); } var viewModel = new RigsListViewModel() { ItemsPerPage = GlobalConstants.RigsCountPerPage, ItemsCount = rigsCount, PageNumber = input.Page, Rigs = rigs, Search = input.Search, CurrOrder = input.Order ?? "Order By", OrderTypes = new string[] { "Order By", "Steps ASC", "Steps DESC", "Trophies ASC", "Trophies DESC", "Materials ASC", "Materials DESC" }, }; return(this.View(viewModel)); }
public IEnumerable <T> GetAll <T>(RigsAllInputModel input) { var query = this.rigsRepository.All().AsQueryable(); switch (input.Order) { case "Steps ASC": query = query.OrderBy(x => x.Steps.Count()); break; case "Steps DESC": query = query.OrderByDescending(x => x.Steps.Count()); break; case "Trophies ASC": query = query.OrderBy(x => x.Trophies.Count()); break; case "Trophies DESC": query = query.OrderByDescending(x => x.Trophies.Count()); break; case "Materials ASC": query = query.OrderBy(x => x.Materials.Count()); break; case "Materials DESC": query = query.OrderByDescending(x => x.Materials.Count()); break; } if (!string.IsNullOrEmpty(input.Search)) { query = query.Where(l => l.Name.ToLower().Contains(input.Search.ToLower())); } return(query .Skip((input.Page - 1) * GlobalConstants.LakesCountPerPage) .Take(GlobalConstants.LakesCountPerPage) .To <T>() .ToList()); }