public async override Task <ActionResult> Index(ContentModel contentModel) { if (contentModel is null) { throw new System.ArgumentNullException(nameof(contentModel)); } var model = new ClubViewModel(contentModel.Content, Services?.UserService) { Club = await _clubDataSource.ReadClubByRoute(Request.RawUrl).ConfigureAwait(false) }; if (model.Club == null) { return(new HttpNotFoundResult()); } else { model.IsAuthorized = _authorizationPolicy.IsAuthorized(model.Club); model.Metadata.PageTitle = model.Club.ClubName; model.Metadata.Description = model.Club.Description(); model.Breadcrumbs.Add(new Breadcrumb { Name = Constants.Pages.Teams, Url = new Uri(Constants.Pages.TeamsUrl, UriKind.Relative) }); return(CurrentTemplate(model)); } }
public async override Task <ActionResult> Index(ContentModel contentModel) { if (contentModel is null) { throw new ArgumentNullException(nameof(contentModel)); } var club = await _clubDataSource.ReadClubByRoute(Request.RawUrl).ConfigureAwait(false); if (club == null) { return(new HttpNotFoundResult()); } else { var filter = _matchFilterFactory.MatchesForTeams(club.Teams.Select(team => team.TeamId.Value).ToList()); var model = new ClubViewModel(contentModel.Content, Services?.UserService) { Club = club, DefaultMatchFilter = filter.filter, Matches = new MatchListingViewModel(contentModel.Content, Services?.UserService) { DateTimeFormatter = _dateFormatter } }; model.AppliedMatchFilter = _matchFilterQueryStringParser.ParseQueryString(model.DefaultMatchFilter, HttpUtility.ParseQueryString(Request.Url.Query)); // Only get matches if there are teams, otherwise matches for all teams will be returned if (model.Club.Teams.Count > 0) { model.Matches.Matches = await _matchDataSource.ReadMatchListings(model.AppliedMatchFilter, filter.sortOrder).ConfigureAwait(false); } model.IsAuthorized = _authorizationPolicy.IsAuthorized(model.Club); var userFilter = _matchFilterHumanizer.MatchingFilter(model.AppliedMatchFilter); if (!string.IsNullOrWhiteSpace(userFilter)) { model.FilterDescription = _matchFilterHumanizer.MatchesAndTournaments(model.AppliedMatchFilter) + userFilter; } model.Metadata.PageTitle = $"{_matchFilterHumanizer.MatchesAndTournaments(model.AppliedMatchFilter)} for {model.Club.ClubName}{userFilter}"; model.Breadcrumbs.Add(new Breadcrumb { Name = Constants.Pages.Teams, Url = new Uri(Constants.Pages.TeamsUrl, UriKind.Relative) }); return(CurrentTemplate(model)); } }
public async Task <ActionResult> UpdateClub([Bind(Prefix = "Club", Include = "ClubName,Teams")] Club club) { if (club is null) { throw new System.ArgumentNullException(nameof(club)); } var beforeUpdate = await _clubDataSource.ReadClubByRoute(Request.RawUrl).ConfigureAwait(false); club.ClubId = beforeUpdate.ClubId; club.ClubRoute = beforeUpdate.ClubRoute; // We're not interested in validating the details of the selected teams foreach (var key in ModelState.Keys.Where(x => x.StartsWith("Club.Teams", StringComparison.OrdinalIgnoreCase))) { ModelState[key].Errors.Clear(); } var isAuthorized = _authorizationPolicy.IsAuthorized(beforeUpdate); if (isAuthorized[AuthorizedAction.EditClub] && ModelState.IsValid) { var currentMember = Members.GetCurrentMember(); var updatedClub = await _clubRepository.UpdateClub(club, currentMember.Key, currentMember.Name).ConfigureAwait(false); _cacheOverride.OverrideCacheForCurrentMember(CacheConstants.TeamListingsCacheKeyPrefix); // redirect back to the club actions page that led here return(Redirect(updatedClub.ClubRoute + "/edit")); } var viewModel = new ClubViewModel(CurrentPage, Services.UserService) { Club = club, }; viewModel.IsAuthorized = isAuthorized; viewModel.Metadata.PageTitle = $"Edit {club.ClubName}"; viewModel.Breadcrumbs.Add(new Breadcrumb { Name = Constants.Pages.Teams, Url = new Uri(Constants.Pages.TeamsUrl, UriKind.Relative) }); viewModel.Breadcrumbs.Add(new Breadcrumb { Name = viewModel.Club.ClubName, Url = new Uri(viewModel.Club.ClubRoute, UriKind.Relative) }); return(View("EditClub", viewModel)); }
public override Task <ActionResult> Index(ContentModel contentModel) { if (contentModel is null) { throw new System.ArgumentNullException(nameof(contentModel)); } var model = new ClubViewModel(contentModel.Content, Services?.UserService) { Club = new Club() }; model.IsAuthorized = _authorizationPolicy.IsAuthorized(model.Club); model.Metadata.PageTitle = "Add a club"; model.Breadcrumbs.Add(new Breadcrumb { Name = Constants.Pages.Teams, Url = new Uri(Constants.Pages.TeamsUrl, UriKind.Relative) }); return(Task.FromResult(CurrentTemplate(model))); }
public async Task <ActionResult> CreateClub([Bind(Prefix = "Club", Include = "ClubName,Teams")] Club club) { if (club is null) { throw new System.ArgumentNullException(nameof(club)); } // We're not interested in validating the details of the selected teams foreach (var key in ModelState.Keys.Where(x => x.StartsWith("Club.Teams", StringComparison.OrdinalIgnoreCase))) { ModelState[key].Errors.Clear(); } var isAuthorized = _authorizationPolicy.IsAuthorized(club); if (isAuthorized[AuthorizedAction.CreateClub] && ModelState.IsValid) { // Create an owner group var groupName = _routeGenerator.GenerateRoute("club", club.ClubName, NoiseWords.ClubRoute); IMemberGroup group; do { group = Services.MemberGroupService.GetByName(groupName); if (group == null) { group = new MemberGroup { Name = groupName }; Services.MemberGroupService.Save(group); club.MemberGroupKey = group.Key; club.MemberGroupName = group.Name; break; } else { groupName = _routeGenerator.IncrementRoute(groupName); } }while (group != null); // Assign the current member to the group unless they're already admin var currentMember = Members.GetCurrentMember(); if (!Members.IsMemberAuthorized(null, new[] { Groups.Administrators }, null)) { Services.MemberService.AssignRole(currentMember.Id, group.Name); } // Create the club var createdClub = await _clubRepository.CreateClub(club, currentMember.Key, currentMember.Name).ConfigureAwait(false); _cacheOverride.OverrideCacheForCurrentMember(CacheConstants.TeamListingsCacheKeyPrefix); // Redirect to the club return(Redirect(createdClub.ClubRoute)); } var viewModel = new ClubViewModel(CurrentPage, Services.UserService) { Club = club, }; viewModel.IsAuthorized = isAuthorized; viewModel.Metadata.PageTitle = $"Add a club"; viewModel.Breadcrumbs.Add(new Breadcrumb { Name = Constants.Pages.Teams, Url = new Uri(Constants.Pages.TeamsUrl, UriKind.Relative) }); return(View("CreateClub", viewModel)); }