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 DeleteSeasonViewModel(contentModel.Content, Services?.UserService) { Season = await _seasonDataSource.ReadSeasonByRoute(Request.RawUrl, true).ConfigureAwait(false) }; if (model.Season == null) { return(new HttpNotFoundResult()); } else { model.TotalMatches = await _matchDataSource.ReadTotalMatches(new MatchFilter { SeasonIds = new List <Guid> { model.Season.SeasonId.Value }, IncludeTournamentMatches = true }).ConfigureAwait(false); model.ConfirmDeleteRequest.RequiredText = model.Season.SeasonFullName(); model.IsAuthorized = _authorizationPolicy.IsAuthorized(model.Season.Competition); model.Metadata.PageTitle = "Delete " + model.Season.SeasonFullNameAndPlayerType(); model.Breadcrumbs.Add(new Breadcrumb { Name = Constants.Pages.Competitions, Url = new Uri(Constants.Pages.CompetitionsUrl, UriKind.Relative) }); model.Breadcrumbs.Add(new Breadcrumb { Name = model.Season.Competition.CompetitionName, Url = new Uri(model.Season.Competition.CompetitionRoute, UriKind.Relative) }); model.Breadcrumbs.Add(new Breadcrumb { Name = model.Season.SeasonName(), Url = new Uri(model.Season.SeasonRoute, UriKind.Relative) }); return(CurrentTemplate(model)); } }