Пример #1
0
        public async Task <IActionResult> Filter(
            [FromServices] ISortingService sortingService,
            string searchTerm = null,
            string postcode   = null,
            string sortBy     = null,
            string openOnly   = null)
        {
            var openFilter = !string.IsNullOrEmpty(openOnly);
            var matches    = await _service.GetSearchedAsync(searchTerm, postcode, openFilter);

            if (matches != null)
            {
                TempData["Filter"] = searchTerm;

                if (!string.IsNullOrWhiteSpace(sortBy) ||
                    !string.IsNullOrWhiteSpace(postcode) ||
                    openFilter)
                {
                    TempData["Sorted"] = "true";
                }
            }
            else
            {
                TempData["Matches"] = "No Matches found";

                matches = await _service.GetAllModelsAsync();
            }

            if (!string.IsNullOrWhiteSpace(sortBy))
            {
                matches = sortingService.SortResults <ParkModel>(matches, sortBy);
            }

            return(View("Index", matches));
        }
Пример #2
0
        public async Task <ActionResult <ParkModel> > GetParkByName(string parkName)
        {
            var results = await _service.GetSearchedAsync(parkName);

            return(Ok(results));
        }