public async Task <ActionResult> DeleteCompetition([Bind(Prefix = "ConfirmDeleteRequest", Include = "RequiredText,ConfirmationText")] MatchingTextConfirmation model)
        {
            if (model is null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var viewModel = new DeleteCompetitionViewModel(CurrentPage, Services.UserService)
            {
                Competition = await _competitionDataSource.ReadCompetitionByRoute(Request.RawUrl).ConfigureAwait(false),
            };

            viewModel.IsAuthorized = _authorizationPolicy.IsAuthorized(viewModel.Competition);

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

                var currentMember = Members.GetCurrentMember();
                await _competitionRepository.DeleteCompetition(viewModel.Competition, currentMember.Key, currentMember.Name).ConfigureAwait(false);

                _cacheOverride.OverrideCacheForCurrentMember(CacheConstants.CompetitionsPolicyCacheKeyPrefix);
                viewModel.Deleted = true;
            }
            else
            {
                var competitionIds = new List <Guid> {
                    viewModel.Competition.CompetitionId.Value
                };
                viewModel.TotalMatches = await _matchDataSource.ReadTotalMatches(new MatchFilter
                {
                    CompetitionIds           = competitionIds,
                    IncludeTournamentMatches = true
                }).ConfigureAwait(false);

                viewModel.TotalTeams = await _teamDataSource.ReadTotalTeams(new TeamFilter
                {
                    CompetitionIds = competitionIds
                }).ConfigureAwait(false);
            }

            viewModel.Metadata.PageTitle = $"Delete {viewModel.Competition.CompetitionName}";

            viewModel.Breadcrumbs.Add(new Breadcrumb {
                Name = Constants.Pages.Competitions, Url = new Uri(Constants.Pages.CompetitionsUrl, UriKind.Relative)
            });
            if (!viewModel.Deleted)
            {
                viewModel.Breadcrumbs.Add(new Breadcrumb {
                    Name = viewModel.Competition.CompetitionName, Url = new Uri(viewModel.Competition.CompetitionRoute, UriKind.Relative)
                });
            }

            return(View("DeleteCompetition", viewModel));
        }
Exemple #2
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));
            }
        }
Exemple #3
0
        public async Task <ActionResult> DeleteSeason([Bind(Prefix = "ConfirmDeleteRequest", Include = "RequiredText,ConfirmationText")] MatchingTextConfirmation model)
        {
            if (model is null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var viewModel = new DeleteSeasonViewModel(CurrentPage, Services.UserService)
            {
                Season = await _seasonDataSource.ReadSeasonByRoute(Request.RawUrl, true).ConfigureAwait(false),
            };

            viewModel.IsAuthorized = _authorizationPolicy.IsAuthorized(viewModel.Season.Competition);

            // Create a version without circular references before it gets serialised for audit
            viewModel.Season.Teams = viewModel.Season.Teams.Select(x => new TeamInSeason {
                Team = x.Team, WithdrawnDate = x.WithdrawnDate
            }).ToList();

            if (viewModel.IsAuthorized[AuthorizedAction.DeleteCompetition] && ModelState.IsValid)
            {
                var currentMember = Members.GetCurrentMember();
                await _seasonRepository.DeleteSeason(viewModel.Season, currentMember.Key, currentMember.Name).ConfigureAwait(false);

                viewModel.Deleted = true;
            }
            else
            {
                viewModel.TotalMatches = await _matchDataSource.ReadTotalMatches(new MatchFilter
                {
                    SeasonIds = new List <Guid> {
                        viewModel.Season.SeasonId.Value
                    },
                    IncludeTournamentMatches = true
                }).ConfigureAwait(false);
            }

            viewModel.Metadata.PageTitle = $"Delete {viewModel.Season.SeasonFullNameAndPlayerType()}";

            viewModel.Breadcrumbs.Add(new Breadcrumb {
                Name = Constants.Pages.Competitions, Url = new Uri(Constants.Pages.CompetitionsUrl, UriKind.Relative)
            });
            viewModel.Breadcrumbs.Add(new Breadcrumb {
                Name = viewModel.Season.Competition.CompetitionName, Url = new Uri(viewModel.Season.Competition.CompetitionRoute, UriKind.Relative)
            });
            if (!viewModel.Deleted)
            {
                viewModel.Breadcrumbs.Add(new Breadcrumb {
                    Name = viewModel.Season.SeasonName(), Url = new Uri(viewModel.Season.SeasonRoute, UriKind.Relative)
                });
            }

            return(View("DeleteSeason", viewModel));
        }
        public async override Task <ActionResult> Index(ContentModel contentModel)
        {
            if (contentModel is null)
            {
                throw new ArgumentNullException(nameof(contentModel));
            }

            var model = new DeleteCompetitionViewModel(contentModel.Content, Services?.UserService)
            {
                Competition = await _competitionDataSource.ReadCompetitionByRoute(Request.RawUrl).ConfigureAwait(false)
            };

            if (model.Competition == null)
            {
                return(new HttpNotFoundResult());
            }
            else
            {
                var competitionIds = new List <Guid> {
                    model.Competition.CompetitionId.Value
                };
                model.TotalMatches = await _matchDataSource.ReadTotalMatches(new MatchFilter
                {
                    CompetitionIds           = competitionIds,
                    IncludeTournamentMatches = true
                }).ConfigureAwait(false);

                model.TotalTeams = await _teamDataSource.ReadTotalTeams(new TeamFilter
                {
                    CompetitionIds = competitionIds
                }).ConfigureAwait(false);

                model.ConfirmDeleteRequest.RequiredText = model.Competition.CompetitionName;

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

                model.Metadata.PageTitle = "Delete " + model.Competition.CompetitionName;

                model.Breadcrumbs.Add(new Breadcrumb {
                    Name = Constants.Pages.Competitions, Url = new Uri(Constants.Pages.CompetitionsUrl, UriKind.Relative)
                });
                model.Breadcrumbs.Add(new Breadcrumb {
                    Name = model.Competition.CompetitionName, Url = new Uri(model.Competition.CompetitionRoute, UriKind.Relative)
                });

                return(CurrentTemplate(model));
            }
        }
        public async override Task <ActionResult> Index(ContentModel contentModel)
        {
            if (contentModel is null)
            {
                throw new System.ArgumentNullException(nameof(contentModel));
            }

            var model = new DeleteMatchLocationViewModel(contentModel.Content, Services?.UserService)
            {
                MatchLocation = await _matchLocationDataSource.ReadMatchLocationByRoute(Request.RawUrl, true).ConfigureAwait(false),
            };

            if (model.MatchLocation == null)
            {
                return(new HttpNotFoundResult());
            }
            else
            {
                model.TotalMatches = await _matchDataSource.ReadTotalMatches(new MatchFilter
                {
                    MatchLocationIds = new List <Guid> {
                        model.MatchLocation.MatchLocationId.Value
                    },
                    IncludeTournamentMatches = true
                }).ConfigureAwait(false);

                model.ConfirmDeleteRequest.RequiredText = model.MatchLocation.NameAndLocalityOrTownIfDifferent();

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

                model.Metadata.PageTitle = "Delete " + model.MatchLocation.NameAndLocalityOrTown();

                model.Breadcrumbs.Add(new Breadcrumb {
                    Name = Constants.Pages.MatchLocations, Url = new Uri(Constants.Pages.MatchLocationsUrl, UriKind.Relative)
                });
                model.Breadcrumbs.Add(new Breadcrumb {
                    Name = model.MatchLocation.NameAndLocalityOrTownIfDifferent(), Url = new Uri(model.MatchLocation.MatchLocationRoute, 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));
        }