public ViewResult Index(string sortOrder, string currentFilter, string searchString, int?page) { ViewBag.CurrentSort = sortOrder; ViewBag.NameSortParm = string.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; var halls = _hallManager.Halls(); if (!string.IsNullOrEmpty(searchString)) { halls = halls.Where(s => s.Name.ToLower().Contains(searchString.ToLower())); } switch (sortOrder) { case "name_desc": halls = halls.OrderByDescending(b => b.Name).ToList(); break; default: halls = halls.OrderBy(b => b.Name).ToList(); break; } const int pageSize = 10; var pageNumber = (page ?? 1); return(View(halls.AsQueryable().ToPagedList(pageNumber, pageSize))); }
public IActionResult GetHalls([FromQuery] int offset = 0, [FromQuery] int limit = 10, [FromQuery] string name = "", [FromQuery] int?buildingId = null, [FromQuery] bool?available = true, [FromQuery] double?minPrice = null, [FromQuery] double?maxPrice = null) { var halls = _hallManager.Halls().Where(b => b.Name.IndexOf(name, StringComparison.CurrentCultureIgnoreCase) != -1 && b.Available == available).Skip(offset).Take(limit); if (buildingId != null) { halls = halls.Where(b => b.BuildingId == buildingId); } if (minPrice != null && maxPrice != null) { halls = halls.Where(h => h.Price >= minPrice && h.Price <= maxPrice); } var hallMapped = _mapper.Map <IEnumerable <HallDTO> >(halls).Select(h => new HALResponse(h).AddLinks(h.GetLinks())); return(Ok(new HALResponse(null).AddLinks(new[] { new Link("self", "/api/halls", null, "GET") }).AddEmbeddedCollection("halls", hallMapped))); }