コード例 #1
0
        public async override Task <ActionResult> Index(ContentModel contentModel)
        {
            if (contentModel is null)
            {
                throw new ArgumentNullException(nameof(contentModel));
            }

            var model = new DeleteTeamViewModel(contentModel.Content, Services?.UserService)
            {
                Team = await _teamDataSource.ReadTeamByRoute(Request.RawUrl, true).ConfigureAwait(false)
            };

            if (model.Team == null)
            {
                return(new HttpNotFoundResult());
            }
            else
            {
                var teamIds = new List <Guid> {
                    model.Team.TeamId.Value
                };
                model.TotalMatches = await _matchDataSource.ReadTotalMatches(new MatchFilter
                {
                    TeamIds = teamIds,
                    IncludeTournamentMatches = true
                }).ConfigureAwait(false);

                model.Team.Players = (await _playerDataSource.ReadPlayerIdentities(new PlayerFilter
                {
                    TeamIds = teamIds
                }).ConfigureAwait(false))?.Select(x => new Player {
                    PlayerIdentities = new List <PlayerIdentity> {
                        x
                    }
                }).ToList();

                model.ConfirmDeleteRequest.RequiredText = model.Team.TeamName;

                model.IsAuthorized = _authorizationPolicy.IsAuthorized(model.Team);

                model.Metadata.PageTitle = "Delete " + model.Team.TeamName;

                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)
                    });
                }
                model.Breadcrumbs.Add(new Breadcrumb {
                    Name = model.Team.TeamName, Url = new Uri(model.Team.TeamRoute, UriKind.Relative)
                });

                return(CurrentTemplate(model));
            }
        }
コード例 #2
0
        public async Task <AutocompleteResultSet> Autocomplete([FromUri] string query, [FromUri] string[] teams)
        {
            if (teams is null)
            {
                throw new ArgumentNullException(nameof(teams));
            }

            var playerQuery = new PlayerFilter {
                Query = query
            };

            foreach (var guid in teams)
            {
                if (guid == null)
                {
                    continue;
                }

                try
                {
                    playerQuery.TeamIds.Add(new Guid(guid));
                }
                catch (FormatException)
                {
                    // ignore that one
                }
            }
            var players = await _playerDataSource.ReadPlayerIdentities(playerQuery).ConfigureAwait(false);

            return(new AutocompleteResultSet
            {
                suggestions = players.Select(x => new AutocompleteResult
                {
                    value = x.PlayerIdentityName,
                    data = new
                    {
                        playerIdentityId = x.PlayerIdentityId.ToString(),
                        playerIdentityName = x.PlayerIdentityName,
                        playerRecord = BuildPlayerRecord(x, playerQuery.TeamIds.Count != 1),
                        teamId = x.Team.TeamId,
                        teamName = x.Team.TeamName
                    }
                })
            });
        }
コード例 #3
0
        public async override Task <ActionResult> Index(ContentModel contentModel)
        {
            if (contentModel is null)
            {
                throw new ArgumentNullException(nameof(contentModel));
            }

            var model = new TeamViewModel(contentModel.Content, Services?.UserService)
            {
                Team = await _teamDataSource.ReadTeamByRoute(Request.Url.AbsolutePath, true).ConfigureAwait(false)
            };

            if (model.Team == null)
            {
                return(new HttpNotFoundResult());
            }
            else
            {
                var identities = await _playerDataSource.ReadPlayerIdentities(new PlayerFilter { TeamIds = new List <Guid> {
                                                                                                     model.Team.TeamId.Value
                                                                                                 } }).ConfigureAwait(false);

                model.Players = identities.Select(x => x.Player).Distinct(new PlayerEqualityComparer()).ToList();
                foreach (var player in model.Players)
                {
                    player.PlayerIdentities = identities.Where(x => x.Player.PlayerId == player.PlayerId).ToList();
                }

                model.Metadata.PageTitle   = "Players for " + model.Team.TeamName + " stoolball team";
                model.Metadata.Description = model.Team.Description();

                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));
            }
        }
        public async Task <ActionResult> DeleteTeam([Bind(Prefix = "ConfirmDeleteRequest", Include = "RequiredText,ConfirmationText")] MatchingTextConfirmation postedModel)
        {
            if (postedModel is null)
            {
                throw new ArgumentNullException(nameof(postedModel));
            }

            var model = new DeleteTeamViewModel(CurrentPage, Services.UserService)
            {
                Team = await _teamDataSource.ReadTeamByRoute(Request.RawUrl, true).ConfigureAwait(false),
            };

            model.IsAuthorized = _authorizationPolicy.IsAuthorized(model.Team);

            if (model.IsAuthorized[AuthorizedAction.DeleteTeam] && ModelState.IsValid)
            {
                var memberGroup = Services.MemberGroupService.GetById(model.Team.MemberGroupKey.Value);
                if (memberGroup != null)
                {
                    Services.MemberGroupService.Delete(memberGroup);
                }

                var currentMember = Members.GetCurrentMember();
                await _teamRepository.DeleteTeam(model.Team, currentMember.Key, currentMember.Name).ConfigureAwait(false);

                _cacheOverride.OverrideCacheForCurrentMember(CacheConstants.TeamListingsCacheKeyPrefix);
                model.Deleted = true;
            }
            else
            {
                var teamIds = new List <Guid> {
                    model.Team.TeamId.Value
                };
                model.TotalMatches = await _matchDataSource.ReadTotalMatches(new MatchFilter
                {
                    TeamIds = teamIds,
                    IncludeTournamentMatches = true
                }).ConfigureAwait(false);

                model.Team.Players = (await _playerDataSource.ReadPlayerIdentities(new PlayerFilter
                {
                    TeamIds = teamIds
                }).ConfigureAwait(false))?.Select(x => new Player {
                    PlayerIdentities = new List <PlayerIdentity> {
                        x
                    }
                }).ToList();
            }

            model.Metadata.PageTitle = $"Delete {model.Team.TeamName}";

            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)
                });
            }
            if (!model.Deleted)
            {
                model.Breadcrumbs.Add(new Breadcrumb {
                    Name = model.Team.TeamName, Url = new Uri(model.Team.TeamRoute, UriKind.Relative)
                });
            }

            return(View("DeleteTeam", model));
        }
コード例 #5
0
        public async override Task <ActionResult> Index(ContentModel contentModel)
        {
            if (contentModel is null)
            {
                throw new ArgumentNullException(nameof(contentModel));
            }

            var model = new DeleteMatchViewModel(contentModel.Content, Services?.UserService)
            {
                Match             = await _matchDataSource.ReadMatchByRoute(Request.RawUrl).ConfigureAwait(false),
                DateTimeFormatter = _dateFormatter
            };

            if (model.Match == null)
            {
                return(new HttpNotFoundResult());
            }
            else
            {
                model.TotalComments = await _matchCommentsDataSource.ReadTotalComments(model.Match.MatchId.Value).ConfigureAwait(false);

                // Find the player identities in the match, then reselect them with details of how many matches they've played
                model.PlayerIdentities = _playerIdentityFinder.PlayerIdentitiesInMatch(model.Match).ToList();
                if (model.PlayerIdentities.Any())
                {
                    model.PlayerIdentities = await _playerDataSource.ReadPlayerIdentities(
                        new PlayerFilter
                    {
                        PlayerIdentityIds = model.PlayerIdentities.Select(x => x.PlayerIdentityId.Value).ToList()
                    }
                        ).ConfigureAwait(false);
                }

                model.ConfirmDeleteRequest.RequiredText = model.Match.MatchName;

                model.IsAuthorized = _authorizationPolicy.IsAuthorized(model.Match);

                model.Metadata.PageTitle = "Delete " + model.Match.MatchFullName(x => _dateFormatter.FormatDate(x, false, false, false)) + " - stoolball match";

                if (model.Match.Season != null)
                {
                    model.Breadcrumbs.Add(new Breadcrumb {
                        Name = Constants.Pages.Competitions, Url = new Uri(Constants.Pages.CompetitionsUrl, UriKind.Relative)
                    });
                    model.Breadcrumbs.Add(new Breadcrumb {
                        Name = model.Match.Season.Competition.CompetitionName, Url = new Uri(model.Match.Season.Competition.CompetitionRoute, UriKind.Relative)
                    });
                    model.Breadcrumbs.Add(new Breadcrumb {
                        Name = model.Match.Season.SeasonName(), Url = new Uri(model.Match.Season.SeasonRoute, UriKind.Relative)
                    });
                }
                else if (model.Match.Tournament != null)
                {
                    model.Breadcrumbs.Add(new Breadcrumb {
                        Name = Constants.Pages.Tournaments, Url = new Uri(Constants.Pages.TournamentsUrl, UriKind.Relative)
                    });
                    model.Breadcrumbs.Add(new Breadcrumb {
                        Name = model.Match.Tournament.TournamentName, Url = new Uri(model.Match.Tournament.TournamentRoute, UriKind.Relative)
                    });
                }
                else
                {
                    model.Breadcrumbs.Add(new Breadcrumb {
                        Name = Constants.Pages.Matches, Url = new Uri(Constants.Pages.MatchesUrl, UriKind.Relative)
                    });
                }
                model.Breadcrumbs.Add(new Breadcrumb {
                    Name = model.Match.MatchName, Url = new Uri(model.Match.MatchRoute, UriKind.Relative)
                });

                return(CurrentTemplate(model));
            }
        }