public async Task <ActionResult> DeleteTournament([Bind(Prefix = "ConfirmDeleteRequest", Include = "RequiredText,ConfirmationText")] MatchingTextConfirmation postedModel) { if (postedModel is null) { throw new ArgumentNullException(nameof(postedModel)); } var model = new DeleteTournamentViewModel(CurrentPage, Services.UserService) { Tournament = await _tournamentDataSource.ReadTournamentByRoute(Request.RawUrl).ConfigureAwait(false), DateTimeFormatter = _dateTimeFormatter }; model.IsAuthorized = _authorizationPolicy.IsAuthorized(model.Tournament); if (model.IsAuthorized[AuthorizedAction.DeleteTournament] && ModelState.IsValid) { var currentMember = Members.GetCurrentMember(); await _tournamentRepository.DeleteTournament(model.Tournament, currentMember.Key, currentMember.Name).ConfigureAwait(false); await _cacheClearer.ClearCacheFor(model.Tournament).ConfigureAwait(false); model.Deleted = true; } else { model.TotalComments = await _commentsDataSource.ReadTotalComments(model.Tournament.TournamentId.Value).ConfigureAwait(false); model.Matches = new MatchListingViewModel(CurrentPage, Services?.UserService) { Matches = await _matchListingDataSource.ReadMatchListings(new MatchFilter { TournamentId = model.Tournament.TournamentId, IncludeTournamentMatches = true, IncludeTournaments = false }, MatchSortOrder.MatchDateEarliestFirst).ConfigureAwait(false) }; } model.Metadata.PageTitle = "Delete " + model.Tournament.TournamentFullNameAndPlayerType(x => _dateTimeFormatter.FormatDate(x, false, false, false)); model.Breadcrumbs.Add(new Breadcrumb { Name = Constants.Pages.Tournaments, Url = new Uri(Constants.Pages.TournamentsUrl, UriKind.Relative) }); if (!model.Deleted) { model.Breadcrumbs.Add(new Breadcrumb { Name = model.Tournament.TournamentName, Url = new Uri(model.Tournament.TournamentRoute, UriKind.Relative) }); } return(View("DeleteTournament", model)); }
public async override Task <ActionResult> Index(ContentModel contentModel) { if (contentModel is null) { throw new System.ArgumentNullException(nameof(contentModel)); } var model = new DeleteTournamentViewModel(contentModel.Content, Services?.UserService) { Tournament = await _tournamentDataSource.ReadTournamentByRoute(Request.RawUrl).ConfigureAwait(false), DateTimeFormatter = _dateFormatter }; if (model.Tournament == null) { return(new HttpNotFoundResult()); } else { model.TotalComments = await _tournamentCommentsDataSource.ReadTotalComments(model.Tournament.TournamentId.Value).ConfigureAwait(false); model.Matches = new MatchListingViewModel(contentModel.Content, Services?.UserService) { Matches = await _matchDataSource.ReadMatchListings(new MatchFilter { TournamentId = model.Tournament.TournamentId, IncludeTournamentMatches = true, IncludeTournaments = false }, MatchSortOrder.MatchDateEarliestFirst).ConfigureAwait(false) }; model.ConfirmDeleteRequest.RequiredText = model.Tournament.TournamentName; model.IsAuthorized = _authorizationPolicy.IsAuthorized(model.Tournament); model.Metadata.PageTitle = "Delete " + model.Tournament.TournamentFullNameAndPlayerType(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)); } }
public async Task <ActionResult> DeleteMatch([Bind(Prefix = "ConfirmDeleteRequest", Include = "RequiredText,ConfirmationText")] MatchingTextConfirmation postedModel) { if (postedModel is null) { throw new ArgumentNullException(nameof(postedModel)); } var model = new DeleteMatchViewModel(CurrentPage, Services.UserService) { Match = await _matchDataSource.ReadMatchByRoute(Request.RawUrl).ConfigureAwait(false), DateTimeFormatter = _dateTimeFormatter }; model.IsAuthorized = _authorizationPolicy.IsAuthorized(model.Match); if (model.IsAuthorized[AuthorizedAction.DeleteMatch] && ModelState.IsValid) { var currentMember = Members.GetCurrentMember(); await _matchRepository.DeleteMatch(model.Match, currentMember.Key, currentMember.Name).ConfigureAwait(false); await _cacheClearer.ClearCacheFor(model.Match).ConfigureAwait(false); model.Deleted = true; } else { model.TotalComments = await _matchCommentsDataSource.ReadTotalComments(model.Match.MatchId.Value).ConfigureAwait(false); } model.Metadata.PageTitle = "Delete " + model.Match.MatchFullName(x => _dateTimeFormatter.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) }); } if (!model.Deleted) { model.Breadcrumbs.Add(new Breadcrumb { Name = model.Match.MatchName, Url = new Uri(model.Match.MatchRoute, UriKind.Relative) }); } return(View("DeleteMatch", model)); }
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)); } }