public async override Task <ActionResult> Index(ContentModel contentModel) { if (contentModel is null) { throw new ArgumentNullException(nameof(contentModel)); } var model = new SeasonViewModel(contentModel.Content, Services?.UserService) { Season = await _seasonDataSource.ReadSeasonByRoute(Request.RawUrl, false).ConfigureAwait(false), GoogleMapsApiKey = _apiKeyProvider.GetApiKey("GoogleMaps") }; if (model.Season == null) { return(new HttpNotFoundResult()); } else { var the = model.Season.Competition.CompetitionName.StartsWith("THE ", StringComparison.OrdinalIgnoreCase); model.Metadata.PageTitle = $"Map of teams in {(the ? string.Empty : "the ")}{model.Season.SeasonFullNameAndPlayerType()}"; model.Metadata.Description = model.Season.Description(); 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) }); return(CurrentTemplate(model)); } }
public async override Task <ActionResult> Index(ContentModel contentModel) { if (contentModel is null) { throw new System.ArgumentNullException(nameof(contentModel)); } var model = new SeasonViewModel(contentModel.Content, Services?.UserService) { Season = await _seasonDataSource.ReadSeasonByRoute(Request.RawUrl).ConfigureAwait(false) }; if (model.Season == null) { return(new HttpNotFoundResult()); } else { model.IsAuthorized = _authorizationPolicy.IsAuthorized(model.Season.Competition); model.Metadata.PageTitle = "Edit " + 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)); } }
public async Task <ActionResult> UpdateSeason([Bind(Prefix = "Season", Include = "Teams")] Season season) { if (season is null) { season = new Season(); // if there are no teams, season is null } var beforeUpdate = await _seasonDataSource.ReadSeasonByRoute(Request.RawUrl).ConfigureAwait(false); season.SeasonId = beforeUpdate.SeasonId; ReplaceDateFormatErrorMessages("Date withdrew"); // We're not interested in validating the details of the selected teams foreach (var key in ModelState.Keys.Where(x => x.StartsWith("Season.Teams", StringComparison.OrdinalIgnoreCase))) { ModelState[key].Errors.Clear(); } var isAuthorized = _authorizationPolicy.IsAuthorized(beforeUpdate.Competition); if (isAuthorized[AuthorizedAction.EditCompetition] && ModelState.IsValid) { // Update the season var currentMember = Members.GetCurrentMember(); await _seasonRepository.UpdateTeams(season, currentMember.Key, currentMember.Name).ConfigureAwait(false); // Redirect to the season actions page that led here return(Redirect(beforeUpdate.SeasonRoute + "/edit")); } var viewModel = new SeasonViewModel(CurrentPage, Services.UserService) { Season = season, }; viewModel.IsAuthorized = isAuthorized; season.Competition = beforeUpdate.Competition; season.FromYear = beforeUpdate.FromYear; season.UntilYear = beforeUpdate.UntilYear; season.SeasonRoute = beforeUpdate.SeasonRoute; viewModel.Metadata.PageTitle = $"Teams in the {beforeUpdate.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) }); viewModel.Breadcrumbs.Add(new Breadcrumb { Name = viewModel.Season.SeasonName(), Url = new Uri(viewModel.Season.SeasonRoute, UriKind.Relative) }); return(View("EditSeasonTeams", viewModel)); }
public async override Task <ActionResult> Index(ContentModel contentModel) { if (contentModel is null) { throw new ArgumentNullException(nameof(contentModel)); } var model = new SeasonViewModel(contentModel.Content, Services?.UserService) { Season = await _seasonDataSource.ReadSeasonByRoute(Request.RawUrl, true).ConfigureAwait(false) }; if (model.Season == null || (!model.Season.MatchTypes.Contains(MatchType.LeagueMatch) && !model.Season.MatchTypes.Contains(MatchType.KnockoutMatch) && !model.Season.MatchTypes.Contains(MatchType.FriendlyMatch) && string.IsNullOrEmpty(model.Season.Results))) { return(new HttpNotFoundResult()); } else { model.Matches = new MatchListingViewModel(contentModel.Content, Services?.UserService) { Matches = await _matchDataSource.ReadMatchListings(new MatchFilter { SeasonIds = new List <Guid> { model.Season.SeasonId.Value }, IncludeTournaments = false }, MatchSortOrder.MatchDateEarliestFirst).ConfigureAwait(false), DateTimeFormatter = _dateTimeFormatter }; model.Season.PointsRules.AddRange(await _seasonDataSource.ReadPointsRules(model.Season.SeasonId.Value).ConfigureAwait(false)); model.Season.PointsAdjustments.AddRange(await _seasonDataSource.ReadPointsAdjustments(model.Season.SeasonId.Value).ConfigureAwait(false)); model.Season.Results = _emailProtector.ProtectEmailAddresses(model.Season.Results, User.Identity.IsAuthenticated); model.IsAuthorized = _authorizationPolicy.IsAuthorized(model.Season.Competition); var the = model.Season.Competition.CompetitionName.StartsWith("THE ", StringComparison.OrdinalIgnoreCase); model.Metadata.PageTitle = $"Results table for {(the ? string.Empty : "the ")}{model.Season.SeasonFullNameAndPlayerType()}"; model.Metadata.Description = model.Season.Description(); 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) }); return(CurrentTemplate(model)); } }
public async Task <ActionResult> UpdateSeason([Bind(Prefix = "Season", Include = "PointsRules,ResultsTableType,EnableRunsScored,EnableRunsConceded")] Season season) { if (season is null) { throw new ArgumentNullException(nameof(season)); } var beforeUpdate = await _seasonDataSource.ReadSeasonByRoute(Request.RawUrl).ConfigureAwait(false); season.SeasonId = beforeUpdate.SeasonId; var isAuthorized = _authorizationPolicy.IsAuthorized(beforeUpdate.Competition); if (isAuthorized[AuthorizedAction.EditCompetition] && ModelState.IsValid) { // Update the season var currentMember = Members.GetCurrentMember(); await _seasonRepository.UpdateResultsTable(season, currentMember.Key, currentMember.Name).ConfigureAwait(false); return(_postSaveRedirector.WorkOutRedirect(beforeUpdate.SeasonRoute, beforeUpdate.SeasonRoute, "/edit", Request.Form["UrlReferrer"], null)); } var viewModel = new SeasonViewModel(CurrentPage, Services.UserService) { Season = season, UrlReferrer = string.IsNullOrEmpty(Request.Form["UrlReferrer"]) ? null : new Uri(Request.Form["UrlReferrer"]) }; viewModel.IsAuthorized = isAuthorized; season.Competition = beforeUpdate.Competition; season.FromYear = beforeUpdate.FromYear; season.UntilYear = beforeUpdate.UntilYear; season.SeasonRoute = beforeUpdate.SeasonRoute; viewModel.Metadata.PageTitle = $"Edit results table for {beforeUpdate.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) }); viewModel.Breadcrumbs.Add(new Breadcrumb { Name = viewModel.Season.SeasonName(), Url = new Uri(viewModel.Season.SeasonRoute, UriKind.Relative) }); return(View("EditSeasonResultsTable", viewModel)); }
public override async Task <ActionResult> Index(ContentModel contentModel) { if (contentModel is null) { throw new ArgumentNullException(nameof(contentModel)); } var competition = await _competitionDataSource.ReadCompetitionByRoute(Request.RawUrl).ConfigureAwait(false); if (competition == null) { return(new HttpNotFoundResult()); } else { var model = new SeasonViewModel(contentModel.Content, Services?.UserService) { Season = competition.Seasons.FirstOrDefault() ?? new Season { PlayersPerTeam = 11 } }; if (!model.Season.DefaultOverSets.Any()) { model.Season.DefaultOverSets.Add(new OverSet()); } var summerSeason = model.Season.FromYear == model.Season.UntilYear; model.Season.Competition = competition; model.Season.FromYear = model.Season.FromYear == default ? DateTime.Today.Year : model.Season.FromYear + 1; model.Season.UntilYear = summerSeason ? 0 : 1; model.IsAuthorized = _authorizationPolicy.IsAuthorized(model.Season.Competition); var the = model.Season.Competition.CompetitionName.StartsWith("THE ", StringComparison.OrdinalIgnoreCase) ? string.Empty : "the "; model.Metadata.PageTitle = $"Add a season in {the}{model.Season.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.Season.Competition.CompetitionName, Url = new Uri(model.Season.Competition.CompetitionRoute, UriKind.Relative) }); return(CurrentTemplate(model)); } }
public async override Task <ActionResult> Index(ContentModel contentModel) { if (contentModel is null) { throw new ArgumentNullException(nameof(contentModel)); } var season = await _seasonDataSource.ReadSeasonByRoute(Request.RawUrl, false).ConfigureAwait(false); if (season == null) { return(new HttpNotFoundResult()); } else { var filter = _matchFilterFactory.MatchesForSeason(season.SeasonId.Value); var model = new SeasonViewModel(contentModel.Content, Services?.UserService) { Season = season, Matches = new MatchListingViewModel(contentModel.Content, Services?.UserService) { Matches = await _matchDataSource.ReadMatchListings(filter.filter, filter.sortOrder).ConfigureAwait(false), DateTimeFormatter = _dateFormatter }, }; if (model.Season.MatchTypes.Contains(MatchType.LeagueMatch) || model.Season.MatchTypes.Contains(MatchType.KnockoutMatch)) { model.Matches.MatchTypesToLabel.Add(MatchType.FriendlyMatch); } model.IsAuthorized = _authorizationPolicy.IsAuthorized(model.Season.Competition); model.Metadata.PageTitle = $"Matches and tournaments in {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) }); return(CurrentTemplate(model)); } }
public async Task <ActionResult> CreateSeason([Bind(Prefix = "Season", Include = "FromYear,UntilYear,EnableTournaments,EnableBonusOrPenaltyRuns,PlayersPerTeam,DefaultOverSets,EnableLastPlayerBatsOn")] Season season) { if (season is null) { throw new System.ArgumentNullException(nameof(season)); } season.DefaultOverSets.RemoveAll(x => !x.Overs.HasValue); // end year is actually populated with the number of years to add to the start year, // because that allows the start year to be changed from the default without using JavaScript // to update the value of the end year radio buttons season.UntilYear = season.FromYear + season.UntilYear; // get this from the unvalidated form instead of via modelbinding so that HTML can be allowed season.Introduction = Request.Unvalidated.Form["Season.Introduction"]; season.Results = Request.Unvalidated.Form["Season.Results"]; try { // parse this because there's no way to get it via the standard modelbinder without requiring JavaScript to change the field names on submit season.MatchTypes = Request.Form["Season.MatchTypes"]?.Split(',').Select(x => (MatchType)Enum.Parse(typeof(MatchType), x)).ToList() ?? new List <MatchType>(); } catch (InvalidCastException) { return(new HttpStatusCodeResult(400)); } if (!season.MatchTypes.Any()) { ModelState.AddModelError("Season.MatchTypes", $"Please select at least one type of match"); } season.Competition = await _competitionDataSource.ReadCompetitionByRoute(Request.RawUrl).ConfigureAwait(false); // Ensure there isn't already a season with the submitted year(s) if (season.Competition.Seasons.Any(x => x.FromYear == season.FromYear && x.UntilYear == season.UntilYear)) { ModelState.AddModelError("Season.FromYear", $"There is already a {season.SeasonName()}"); } var isAuthorized = _authorizationPolicy.IsAuthorized(season.Competition); if (isAuthorized[AuthorizedAction.EditCompetition] && ModelState.IsValid) { // Create the season var currentMember = Members.GetCurrentMember(); var createdSeason = await _seasonRepository.CreateSeason(season, currentMember.Key, currentMember.Name).ConfigureAwait(false); // Redirect to the season return(Redirect(createdSeason.SeasonRoute)); } var viewModel = new SeasonViewModel(CurrentPage, Services.UserService) { Season = season, }; viewModel.IsAuthorized = isAuthorized; var the = season.Competition.CompetitionName.StartsWith("THE ", StringComparison.OrdinalIgnoreCase) ? string.Empty : "the "; viewModel.Metadata.PageTitle = $"Add a season in {the}{season.Competition.CompetitionName}"; 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) }); return(View("CreateSeason", viewModel)); }
public async Task <ActionResult> UpdateSeason([Bind(Prefix = "Season", Include = "EnableTournaments,PlayersPerTeam,DefaultOverSets,EnableLastPlayerBatsOn,EnableBonusOrPenaltyRuns")] Season season) { if (season is null) { throw new ArgumentNullException(nameof(season)); } var beforeUpdate = await _seasonDataSource.ReadSeasonByRoute(Request.RawUrl).ConfigureAwait(false); season.DefaultOverSets.RemoveAll(x => !x.Overs.HasValue); // get this from the unvalidated form instead of via modelbinding so that HTML can be allowed season.SeasonId = beforeUpdate.SeasonId; season.Introduction = Request.Unvalidated.Form["Season.Introduction"]; season.Results = Request.Unvalidated.Form["Season.Results"]; try { // parse this because there's no way to get it via the standard modelbinder without requiring JavaScript to change the field names on submit season.MatchTypes = Request.Form["Season.MatchTypes"]?.Split(',').Select(x => (MatchType)Enum.Parse(typeof(MatchType), x)).ToList() ?? new List <MatchType>(); } catch (InvalidCastException) { return(new HttpStatusCodeResult(400)); } if (!season.MatchTypes.Any()) { ModelState.AddModelError("Season.MatchTypes", $"Please select at least one type of match"); } var isAuthorized = _authorizationPolicy.IsAuthorized(beforeUpdate.Competition); if (isAuthorized[AuthorizedAction.EditCompetition] && ModelState.IsValid) { // Update the season var currentMember = Members.GetCurrentMember(); await _seasonRepository.UpdateSeason(season, currentMember.Key, currentMember.Name).ConfigureAwait(false); // Redirect to the season actions page that led here return(Redirect(beforeUpdate.SeasonRoute + "/edit")); } var viewModel = new SeasonViewModel(CurrentPage, Services.UserService) { Season = beforeUpdate, }; viewModel.IsAuthorized = isAuthorized; viewModel.Metadata.PageTitle = $"Edit {beforeUpdate.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) }); viewModel.Breadcrumbs.Add(new Breadcrumb { Name = viewModel.Season.SeasonName(), Url = new Uri(viewModel.Season.SeasonRoute, UriKind.Relative) }); return(View("EditSeason", viewModel)); }