public async Task ClearCacheFor(Tournament tournament)
        {
            if (tournament == null)
            {
                throw new ArgumentNullException(nameof(tournament));
            }

            var affectedTeams = tournament.Teams.Select(t => t.Team.TeamId.Value).ToList();

            foreach (var teamId in affectedTeams)
            {
                var filter = _matchFilterFactory.MatchesForTeams(new List <Guid> {
                    teamId
                });
                var cacheKey = CacheConstants.MatchListingsCacheKeyPrefix + _matchFilterSerializer.Serialize(filter.filter) + filter.sortOrder;
                _cache.Remove(cacheKey);
            }

            if (affectedTeams.Any())
            {
                var clubs = await _clubDataSource.ReadClubs(new ClubFilter { TeamIds = affectedTeams }).ConfigureAwait(false);

                foreach (var club in clubs)
                {
                    var filter   = _matchFilterFactory.MatchesForTeams(club.Teams.Select(x => x.TeamId.Value).ToList());
                    var cacheKey = CacheConstants.MatchListingsCacheKeyPrefix + _matchFilterSerializer.Serialize(filter.filter) + filter.sortOrder;
                    _cache.Remove(cacheKey);
                }
            }

            if (tournament.TournamentLocation != null)
            {
                var filter   = _matchFilterFactory.MatchesForMatchLocation(tournament.TournamentLocation.MatchLocationId.Value);
                var cacheKey = CacheConstants.MatchListingsCacheKeyPrefix + _matchFilterSerializer.Serialize(filter.filter) + filter.sortOrder;
                _cache.Remove(cacheKey);
            }

            if (tournament.Seasons != null)
            {
                foreach (var season in tournament.Seasons)
                {
                    var filter   = _matchFilterFactory.MatchesForSeason(season.SeasonId.Value);
                    var cacheKey = CacheConstants.MatchListingsCacheKeyPrefix + _matchFilterSerializer.Serialize(filter.filter) + filter.sortOrder;
                    _cache.Remove(cacheKey);
                }
            }

            if (tournament != null)
            {
                var filter   = _matchFilterFactory.MatchesForTournament(tournament.TournamentId.Value);
                var cacheKey = CacheConstants.MatchListingsCacheKeyPrefix + _matchFilterSerializer.Serialize(filter.filter) + filter.sortOrder;
                _cache.Remove(cacheKey);
            }
        }
        public async override Task <ActionResult> Index(ContentModel contentModel)
        {
            if (contentModel is null)
            {
                throw new ArgumentNullException(nameof(contentModel));
            }

            var team = await _teamDataSource.ReadTeamByRoute(Request.RawUrl, true).ConfigureAwait(false);

            if (team == null)
            {
                return(new HttpNotFoundResult());
            }
            else
            {
                var filter = _matchFilterFactory.MatchesForTeams(new List <Guid> {
                    team.TeamId.Value
                });
                var model = new TeamViewModel(contentModel.Content, Services?.UserService)
                {
                    Team = team,
                    DefaultMatchFilter = filter.filter,
                    Matches            = new MatchListingViewModel(contentModel.Content, Services?.UserService)
                    {
                        DateTimeFormatter = _dateFormatter
                    },
                };
                model.AppliedMatchFilter = _matchFilterQueryStringParser.ParseQueryString(model.DefaultMatchFilter, HttpUtility.ParseQueryString(Request.Url.Query));
                model.Matches.Matches    = await _matchDataSource.ReadMatchListings(model.AppliedMatchFilter, filter.sortOrder).ConfigureAwait(false);

                model.IsAuthorized       = _authorizationPolicy.IsAuthorized(model.Team);
                model.IsInACurrentLeague = _createMatchSeasonSelector.SelectPossibleSeasons(model.Team.Seasons, MatchType.LeagueMatch).Any();
                model.IsInACurrentKnockoutCompetition = _createMatchSeasonSelector.SelectPossibleSeasons(model.Team.Seasons, MatchType.KnockoutMatch).Any();

                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.Team.TeamName} stoolball team{userFilter}";

                model.Breadcrumbs.Add(new Breadcrumb {
                    Name = Constants.Pages.Teams, Url = new Uri(Constants.Pages.TeamsUrl, UriKind.Relative)
                });
                if (model.Team.Club != null)
                {
                    model.Breadcrumbs.Add(new Breadcrumb {
                        Name = model.Team.Club.ClubName, Url = new Uri(model.Team.Club.ClubRoute, UriKind.Relative)
                    });
                }

                return(CurrentTemplate(model));
            }
        }
Пример #3
0
        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));
            }
        }