示例#1
0
        public async Task <IActionResult> Filter(
            [FromServices] ISortingService sortingService,
            string searchTerm = null,
            string parkFilter = null,
            string sportType  = null,
            string sortBy     = null)
        {
            ViewData["Sports"] = _service.GetSportListItems();

            var matches = await _service.GetSearchedSportsClubModelsAsync(
                searchTerm, parkFilter, sportType);

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

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

                matches = await _service.GetAllSportsClubModelsAsync();
            }

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

            return(View("Index", matches));
        }
        public async Task <ActionResult <SportsClubModel[]> > GetAllSportsClubs()
        {
            var results = await _service.GetAllSportsClubModelsAsync();

            return(Ok(results));
        }