public async Task <AutocompleteResultSet> Autocomplete([FromUri] string query = null, [FromUri] string[] matchType = null) { var competitionQuery = new CompetitionFilter { Query = query }; if (matchType != null) { foreach (var mt in matchType) { if (mt == null) { continue; } try { competitionQuery.MatchTypes.Add((MatchType)Enum.Parse(typeof(MatchType), mt, true)); } catch (ArgumentException) { // ignore that one } } } var seasons = await _seasonDataSource.ReadSeasons(competitionQuery).ConfigureAwait(false); return(new AutocompleteResultSet { suggestions = seasons.Select(x => new AutocompleteResult { value = x.SeasonFullName(), data = x.SeasonId.ToString() }) }); }
public async override Task <ActionResult> Index(ContentModel contentModel) { if (contentModel is null) { throw new ArgumentNullException(nameof(contentModel)); } var model = new EditTournamentViewModel(contentModel.Content, Services?.UserService) { Tournament = await _tournamentDataSource.ReadTournamentByRoute(Request.RawUrl).ConfigureAwait(false), DateFormatter = _dateFormatter, UrlReferrer = Request.UrlReferrer }; if (model.Tournament == null) { return(new HttpNotFoundResult()); } else { // By filtering for all match types it excludes seasons for annual tournaments like Expo and Seaford, which may support training sessions // but otherwise no match types. Although those tournaments can be listed in other seasons (they're of interest to the league teams), we // don't want other tournaments listed on pages which are supposed to be just about those annual tournaments. For any tournaments which // actually are meant to be in those seasons, they will be added back when the tournament's current seasons are added to the list. var seasonDates = _seasonEstimator.EstimateSeasonDates(model.Tournament.StartTime); var filter = new CompetitionFilter { FromYear = seasonDates.fromDate.Year, UntilYear = seasonDates.untilDate.Year, PlayerTypes = new List <PlayerType> { model.Tournament.PlayerType }, MatchTypes = new List <MatchType> { MatchType.FriendlyMatch, MatchType.KnockoutMatch, MatchType.LeagueMatch }, EnableTournaments = true }; model.PossibleSeasons.AddRange(await _seasonDataSource.ReadSeasons(filter).ConfigureAwait(false)); foreach (var season in model.Tournament.Seasons) { if (!model.PossibleSeasons.Select(x => x.SeasonId.Value).Contains(season.SeasonId.Value)) { model.PossibleSeasons.Add(season); } } model.PossibleSeasons.Sort(new SeasonComparer()); model.IsAuthorized = _authorizationPolicy.IsAuthorized(model.Tournament); model.TournamentDate = model.Tournament.StartTime; model.Metadata.PageTitle = "Where to list " + model.Tournament.TournamentFullName(x => _dateFormatter.FormatDate(x, false, false, false)); model.Breadcrumbs.Add(new Breadcrumb { Name = Constants.Pages.Tournaments, Url = new Uri(Constants.Pages.TournamentsUrl, UriKind.Relative) }); model.Breadcrumbs.Add(new Breadcrumb { Name = model.Tournament.TournamentName, Url = new Uri(model.Tournament.TournamentRoute, UriKind.Relative) }); return(CurrentTemplate(model)); } }