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)); } }
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)); }