public async override Task <ActionResult> Index(ContentModel contentModel) { if (contentModel is null) { throw new System.ArgumentNullException(nameof(contentModel)); } var model = new ClubViewModel(contentModel.Content, Services?.UserService) { Club = await _clubDataSource.ReadClubByRoute(Request.RawUrl).ConfigureAwait(false) }; if (model.Club == null) { return(new HttpNotFoundResult()); } else { model.IsAuthorized = _authorizationPolicy.IsAuthorized(model.Club); model.Metadata.PageTitle = model.Club.ClubName; model.Metadata.Description = model.Club.Description(); model.Breadcrumbs.Add(new Breadcrumb { Name = Constants.Pages.Teams, Url = new Uri(Constants.Pages.TeamsUrl, UriKind.Relative) }); return(CurrentTemplate(model)); } }
public async override Task <ActionResult> Index(ContentModel contentModel) { if (contentModel is null) { throw new ArgumentNullException(nameof(contentModel)); } var club = await _clubDataSource.ReadClubByRoute(Request.RawUrl).ConfigureAwait(false); if (club == null) { return(new HttpNotFoundResult()); } else { var filter = _matchFilterFactory.MatchesForTeams(club.Teams.Select(team => team.TeamId.Value).ToList()); var model = new ClubViewModel(contentModel.Content, Services?.UserService) { Club = club, DefaultMatchFilter = filter.filter, Matches = new MatchListingViewModel(contentModel.Content, Services?.UserService) { DateTimeFormatter = _dateFormatter } }; model.AppliedMatchFilter = _matchFilterQueryStringParser.ParseQueryString(model.DefaultMatchFilter, HttpUtility.ParseQueryString(Request.Url.Query)); // Only get matches if there are teams, otherwise matches for all teams will be returned if (model.Club.Teams.Count > 0) { model.Matches.Matches = await _matchDataSource.ReadMatchListings(model.AppliedMatchFilter, filter.sortOrder).ConfigureAwait(false); } model.IsAuthorized = _authorizationPolicy.IsAuthorized(model.Club); var userFilter = _matchFilterHumanizer.MatchingFilter(model.AppliedMatchFilter); if (!string.IsNullOrWhiteSpace(userFilter)) { model.FilterDescription = _matchFilterHumanizer.MatchesAndTournaments(model.AppliedMatchFilter) + userFilter; } model.Metadata.PageTitle = $"{_matchFilterHumanizer.MatchesAndTournaments(model.AppliedMatchFilter)} for {model.Club.ClubName}{userFilter}"; model.Breadcrumbs.Add(new Breadcrumb { Name = Constants.Pages.Teams, Url = new Uri(Constants.Pages.TeamsUrl, UriKind.Relative) }); return(CurrentTemplate(model)); } }
public async Task <ActionResult> UpdateClub([Bind(Prefix = "Club", Include = "ClubName,Teams")] Club club) { if (club is null) { throw new System.ArgumentNullException(nameof(club)); } var beforeUpdate = await _clubDataSource.ReadClubByRoute(Request.RawUrl).ConfigureAwait(false); club.ClubId = beforeUpdate.ClubId; club.ClubRoute = beforeUpdate.ClubRoute; // We're not interested in validating the details of the selected teams foreach (var key in ModelState.Keys.Where(x => x.StartsWith("Club.Teams", StringComparison.OrdinalIgnoreCase))) { ModelState[key].Errors.Clear(); } var isAuthorized = _authorizationPolicy.IsAuthorized(beforeUpdate); if (isAuthorized[AuthorizedAction.EditClub] && ModelState.IsValid) { var currentMember = Members.GetCurrentMember(); var updatedClub = await _clubRepository.UpdateClub(club, currentMember.Key, currentMember.Name).ConfigureAwait(false); _cacheOverride.OverrideCacheForCurrentMember(CacheConstants.TeamListingsCacheKeyPrefix); // redirect back to the club actions page that led here return(Redirect(updatedClub.ClubRoute + "/edit")); } var viewModel = new ClubViewModel(CurrentPage, Services.UserService) { Club = club, }; viewModel.IsAuthorized = isAuthorized; viewModel.Metadata.PageTitle = $"Edit {club.ClubName}"; viewModel.Breadcrumbs.Add(new Breadcrumb { Name = Constants.Pages.Teams, Url = new Uri(Constants.Pages.TeamsUrl, UriKind.Relative) }); viewModel.Breadcrumbs.Add(new Breadcrumb { Name = viewModel.Club.ClubName, Url = new Uri(viewModel.Club.ClubRoute, UriKind.Relative) }); return(View("EditClub", viewModel)); }
public async Task <ActionResult> DeleteClub([Bind(Prefix = "ConfirmDeleteRequest", Include = "RequiredText,ConfirmationText")] MatchingTextConfirmation model) { if (model is null) { throw new System.ArgumentNullException(nameof(model)); } var viewModel = new DeleteClubViewModel(CurrentPage, Services.UserService) { Club = await _clubDataSource.ReadClubByRoute(Request.RawUrl).ConfigureAwait(false), }; viewModel.IsAuthorized = _authorizationPolicy.IsAuthorized(viewModel.Club); if (viewModel.IsAuthorized[AuthorizedAction.DeleteClub] && ModelState.IsValid) { var memberGroup = Services.MemberGroupService.GetById(viewModel.Club.MemberGroupKey.Value); if (memberGroup != null) { Services.MemberGroupService.Delete(memberGroup); } var currentMember = Members.GetCurrentMember(); await _clubRepository.DeleteClub(viewModel.Club, currentMember.Key, currentMember.Name).ConfigureAwait(false); _cacheOverride.OverrideCacheForCurrentMember(CacheConstants.TeamListingsCacheKeyPrefix); viewModel.Deleted = true; } viewModel.Metadata.PageTitle = $"Delete {viewModel.Club.ClubName}"; viewModel.Breadcrumbs.Add(new Breadcrumb { Name = Constants.Pages.Teams, Url = new Uri(Constants.Pages.TeamsUrl, UriKind.Relative) }); if (!viewModel.Deleted) { viewModel.Breadcrumbs.Add(new Breadcrumb { Name = viewModel.Club.ClubName, Url = new Uri(viewModel.Club.ClubRoute, UriKind.Relative) }); } return(View("DeleteClub", viewModel)); }
public async override Task <ActionResult> Index(ContentModel contentModel) { if (contentModel is null) { throw new ArgumentNullException(nameof(contentModel)); } var model = new StatisticsSummaryViewModel <Club>(contentModel.Content, Services?.UserService) { Context = await _clubDataSource.ReadClubByRoute(Request.RawUrl).ConfigureAwait(false), }; if (model.Context == null) { return(new HttpNotFoundResult()); } else { model.DefaultFilter = new StatisticsFilter { Club = model.Context, MaxResultsAllowingExtraResultsIfValuesAreEqual = 10 }; model.AppliedFilter = _statisticsFilterQueryStringParser.ParseQueryString(model.DefaultFilter, HttpUtility.ParseQueryString(Request.Url.Query)); model.InningsStatistics = await _inningsStatisticsDataSource.ReadInningsStatistics(model.AppliedFilter).ConfigureAwait(false); model.PlayerInnings = (await _bestPerformanceDataSource.ReadPlayerInnings(model.AppliedFilter, StatisticsSortOrder.BestFirst).ConfigureAwait(false)).ToList(); model.BowlingFigures = (await _bestPerformanceDataSource.ReadBowlingFigures(model.AppliedFilter, StatisticsSortOrder.BestFirst).ConfigureAwait(false)).ToList(); model.MostRuns = (await _bestPlayerTotalDataSource.ReadMostRunsScored(model.AppliedFilter).ConfigureAwait(false)).ToList(); model.MostWickets = (await _bestPlayerTotalDataSource.ReadMostWickets(model.AppliedFilter).ConfigureAwait(false)).ToList(); model.MostCatches = (await _bestPlayerTotalDataSource.ReadMostCatches(model.AppliedFilter).ConfigureAwait(false)).ToList(); model.Breadcrumbs.Add(new Breadcrumb { Name = Constants.Pages.Teams, Url = new Uri(Constants.Pages.TeamsUrl, UriKind.Relative) }); model.FilterDescription = _statisticsFilterHumanizer.EntitiesMatchingFilter("Statistics", _statisticsFilterHumanizer.MatchingUserFilter(model.AppliedFilter)); model.Metadata.PageTitle = $"Statistics for {model.Context.ClubName}" + _statisticsFilterHumanizer.MatchingUserFilter(model.AppliedFilter); model.Metadata.Description = $"Statistics for matches played by all teams in {model.Context.ClubName}."; return(CurrentTemplate(model)); } }
public async Task <StatisticsFilter> FromRoute(string route) { if (string.IsNullOrWhiteSpace(route)) { throw new ArgumentException($"'{nameof(route)}' cannot be null or whitespace.", nameof(route)); } var entityType = _stoolballEntityRouteParser.ParseRoute(route); var filter = new StatisticsFilter { Paging = new Paging { PageSize = Constants.Defaults.PageSize } }; if (entityType == StoolballEntityType.Player) { filter.Player = await _playerDataSource.ReadPlayerByRoute(_routeNormaliser.NormaliseRouteToEntity(route, "players")).ConfigureAwait(false); } else if (entityType == StoolballEntityType.Club) { filter.Club = await _clubDataSource.ReadClubByRoute(_routeNormaliser.NormaliseRouteToEntity(route, "clubs")).ConfigureAwait(false); } else if (entityType == StoolballEntityType.Team) { filter.Team = await _teamDataSource.ReadTeamByRoute(_routeNormaliser.NormaliseRouteToEntity(route, "teams"), true).ConfigureAwait(false); // true gets a lot of data but we only really want the club } else if (entityType == StoolballEntityType.MatchLocation) { filter.MatchLocation = await _matchLocationDataSource.ReadMatchLocationByRoute(_routeNormaliser.NormaliseRouteToEntity(route, "locations"), false).ConfigureAwait(false); } else if (entityType == StoolballEntityType.Season) { filter.Season = await _seasonDataSource.ReadSeasonByRoute(_routeNormaliser.NormaliseRouteToEntity(route, "competitions", Constants.Pages.SeasonUrlRegEx)).ConfigureAwait(false); } else if (entityType == StoolballEntityType.Competition) { filter.Competition = await _competitionDataSource.ReadCompetitionByRoute(_routeNormaliser.NormaliseRouteToEntity(route, "competitions")).ConfigureAwait(false); } return(filter); }
public async override Task <ActionResult> Index(ContentModel contentModel) { if (contentModel is null) { throw new ArgumentNullException(nameof(contentModel)); } var model = new MatchListingViewModel(contentModel.Content, Services?.UserService) { DefaultMatchFilter = new MatchFilter { FromDate = DateTimeOffset.UtcNow.Date, IncludeMatches = true, IncludeTournaments = true, IncludeTournamentMatches = false }, DateTimeFormatter = _dateFormatter }; model.AppliedMatchFilter = _matchFilterQueryStringParser.ParseQueryString(model.DefaultMatchFilter, HttpUtility.ParseQueryString(Request.Url.Query)); // Don't allow matches in the past - this is a calendar for planning future events if (model.AppliedMatchFilter.FromDate < model.DefaultMatchFilter.FromDate) { model.AppliedMatchFilter.FromDate = model.DefaultMatchFilter.FromDate; } var pageTitle = "Stoolball matches and tournaments"; var legacyTournamentsCalendarUrl = Regex.Match(Request.RawUrl, "/tournaments/(all|mixed|ladies|junior)/calendar.ics", RegexOptions.IgnoreCase); if (Request.RawUrl.StartsWith("/matches.ics", StringComparison.OrdinalIgnoreCase)) { model.AppliedMatchFilter.IncludeTournaments = false; pageTitle = "Stoolball matches"; } else if (legacyTournamentsCalendarUrl.Success || Request.RawUrl.StartsWith("/tournaments.ics", StringComparison.OrdinalIgnoreCase)) { model.AppliedMatchFilter.IncludeMatches = false; pageTitle = "Stoolball tournaments"; if (legacyTournamentsCalendarUrl.Success) { switch (legacyTournamentsCalendarUrl.Groups[1].Value.ToUpperInvariant()) { case "MIXED": model.AppliedMatchFilter.PlayerTypes.Add(PlayerType.Mixed); break; case "LADIES": model.AppliedMatchFilter.PlayerTypes.Add(PlayerType.Ladies); break; case "JUNIOR": model.AppliedMatchFilter.PlayerTypes.Add(PlayerType.JuniorMixed); model.AppliedMatchFilter.PlayerTypes.Add(PlayerType.JuniorGirls); model.AppliedMatchFilter.PlayerTypes.Add(PlayerType.JuniorBoys); break; default: break; } } } else if (Request.RawUrl.StartsWith("/tournaments/", StringComparison.OrdinalIgnoreCase)) { var tournament = await _tournamentDataSource.ReadTournamentByRoute(Request.RawUrl).ConfigureAwait(false); if (tournament == null) { return(new HttpNotFoundResult()); } pageTitle = tournament.TournamentFullName(x => tournament.StartTimeIsKnown ? _dateFormatter.FormatDateTime(tournament.StartTime, true, false) : _dateFormatter.FormatDate(tournament.StartTime, true, false)); model.Matches.Add(tournament.ToMatchListing()); } else if (Request.RawUrl.StartsWith("/matches/", StringComparison.OrdinalIgnoreCase)) { var match = await _matchDataSource.ReadMatchByRoute(Request.RawUrl).ConfigureAwait(false); if (match == null) { return(new HttpNotFoundResult()); } pageTitle = match.MatchFullName(x => match.StartTimeIsKnown ? _dateFormatter.FormatDateTime(match.StartTime, true, false) : _dateFormatter.FormatDate(match.StartTime, true, false)); model.Matches.Add(match.ToMatchListing()); } else if (Request.RawUrl.StartsWith("/clubs/", StringComparison.OrdinalIgnoreCase)) { var club = await _clubDataSource.ReadClubByRoute(Request.RawUrl).ConfigureAwait(false); if (club == null) { return(new HttpNotFoundResult()); } pageTitle += " for " + club.ClubName; model.AppliedMatchFilter.TeamIds.AddRange(club.Teams.Select(x => x.TeamId.Value)); } else if (Request.RawUrl.StartsWith("/teams/", StringComparison.OrdinalIgnoreCase)) { var team = await _teamDataSource.ReadTeamByRoute(Request.RawUrl).ConfigureAwait(false); if (team == null) { return(new HttpNotFoundResult()); } pageTitle += " for " + team.TeamName; model.AppliedMatchFilter.TeamIds.Add(team.TeamId.Value); } else if (Request.RawUrl.StartsWith("/competitions/", StringComparison.OrdinalIgnoreCase)) { var competition = await _competitionDataSource.ReadCompetitionByRoute(Request.RawUrl).ConfigureAwait(false); if (competition == null) { return(new HttpNotFoundResult()); } pageTitle += " in the " + competition.CompetitionName; model.AppliedMatchFilter.CompetitionIds.Add(competition.CompetitionId.Value); } else if (Request.RawUrl.StartsWith("/locations/", StringComparison.OrdinalIgnoreCase)) { var location = await _matchLocationDataSource.ReadMatchLocationByRoute(Request.RawUrl).ConfigureAwait(false); if (location == null) { return(new HttpNotFoundResult()); } pageTitle += " at " + location.NameAndLocalityOrTown(); model.AppliedMatchFilter.MatchLocationIds.Add(location.MatchLocationId.Value); } // Remove from date from filter if it's the default, and describe the remainder in the feed title. var clonedFilter = model.AppliedMatchFilter.Clone(); if (clonedFilter.FromDate == model.DefaultMatchFilter.FromDate) { clonedFilter.FromDate = null; } model.Metadata.PageTitle = pageTitle + _matchFilterHumanizer.MatchingFilter(clonedFilter); if (model.AppliedMatchFilter.PlayerTypes.Any()) { model.Metadata.PageTitle = $"{model.AppliedMatchFilter.PlayerTypes.First().Humanize(LetterCasing.Sentence).Replace("Junior mixed", "Junior")} {model.Metadata.PageTitle.ToLower(CultureInfo.CurrentCulture)}"; } if (!model.Matches.Any()) { model.Matches = await _matchListingDataSource.ReadMatchListings(model.AppliedMatchFilter, MatchSortOrder.LatestUpdateFirst).ConfigureAwait(false); } return(CurrentTemplate(model)); }
public async override Task <ActionResult> Index(ContentModel contentModel) { if (contentModel is null) { throw new ArgumentNullException(nameof(contentModel)); } var model = new MatchListingViewModel(contentModel.Content, Services?.UserService) { AppliedMatchFilter = _queryStringParser.ParseFilterFromQueryString(Request.QueryString), DateTimeFormatter = _dateFormatter }; string pageTitle = "Stoolball matches"; if (Request.RawUrl.StartsWith("/clubs/", StringComparison.OrdinalIgnoreCase)) { var club = await _clubDataSource.ReadClubByRoute(Request.RawUrl).ConfigureAwait(false); if (club == null) { return(new HttpNotFoundResult()); } pageTitle += " for " + club.ClubName; model.AppliedMatchFilter.TeamIds.AddRange(club.Teams.Select(x => x.TeamId.Value)); } else if (Request.RawUrl.StartsWith("/teams/", StringComparison.OrdinalIgnoreCase)) { var team = await _teamDataSource.ReadTeamByRoute(Request.RawUrl).ConfigureAwait(false); if (team == null) { return(new HttpNotFoundResult()); } pageTitle += " for " + team.TeamName; model.AppliedMatchFilter.TeamIds.Add(team.TeamId.Value); } else if (Request.RawUrl.StartsWith("/competitions/", StringComparison.OrdinalIgnoreCase)) { var competition = await _competitionDataSource.ReadCompetitionByRoute(Request.RawUrl).ConfigureAwait(false); if (competition == null) { return(new HttpNotFoundResult()); } pageTitle += " in the " + competition.CompetitionName; model.AppliedMatchFilter.CompetitionIds.Add(competition.CompetitionId.Value); } else if (Request.RawUrl.StartsWith("/locations/", StringComparison.OrdinalIgnoreCase)) { var location = await _matchLocationDataSource.ReadMatchLocationByRoute(Request.RawUrl).ConfigureAwait(false); if (location == null) { return(new HttpNotFoundResult()); } pageTitle += " at " + location.NameAndLocalityOrTown(); model.AppliedMatchFilter.MatchLocationIds.Add(location.MatchLocationId.Value); } // Remove from date from filter if it's the default, and describe the remainder in the feed title. var clonedFilter = model.AppliedMatchFilter.Clone(); if (clonedFilter.FromDate == DateTimeOffset.UtcNow.Date) { clonedFilter.FromDate = null; } // Remove to date filter if it's a rolling date // (if user has set a specific end date a exactly year in the future unfortunately we'll miss it, but this is only for the description) if (clonedFilter.UntilDate == DateTimeOffset.UtcNow.Date.AddDays(365).AddDays(1).AddSeconds(-1)) { clonedFilter.UntilDate = null; } model.Metadata.PageTitle = pageTitle + _matchFilterHumanizer.MatchingFilter(clonedFilter); model.Metadata.Description = $"New or updated stoolball matches on the Stoolball England website"; if (model.AppliedMatchFilter.PlayerTypes.Any()) { model.Metadata.PageTitle = $"{model.AppliedMatchFilter.PlayerTypes.First().Humanize(LetterCasing.Sentence)} {model.Metadata.PageTitle.ToLower(CultureInfo.CurrentCulture)}"; model.Metadata.Description = $"New or updated {model.AppliedMatchFilter.PlayerTypes.First()} stoolball matches on the Stoolball England website"; } model.Matches = await _matchDataSource.ReadMatchListings(model.AppliedMatchFilter, MatchSortOrder.LatestUpdateFirst).ConfigureAwait(false); return(View(Request.QueryString["format"] == "tweet" ? "MatchTweets" : "MatchesRss", model)); }