public static IEnumerable <string> DuplicatePlayerValidator(ScoreEntryInfo scoreEntryInfo) { HashSet <int> playerIdsForTeam1 = new HashSet <int>(); HashSet <int> playerIdsForTeam2 = new HashSet <int>(); string errorMessage = "A player can only play once per team matchup. Verify that each player is only playing once."; foreach (var match in scoreEntryInfo.TeamMatchupWithMatches.Matches) { int team1PlayerId = match.Result1 == null || !match.Result1.PlayerId.HasValue ? -1 : match.Result1.PlayerId.Value; int team2PlayerId = match.Result2 == null || !match.Result2.PlayerId.HasValue ? -1 : match.Result2.PlayerId.Value; // players 1 and 2 are special no show players. bool error = !TryAddToSet(playerIdsForTeam1, team1PlayerId) || !TryAddToSet(playerIdsForTeam2, team2PlayerId); if (error) { return(new List <string> { errorMessage }); } } return(new LinkedList <string>()); }
public static IEnumerable <string> VerifyMatchComplete(ScoreEntryInfo scoreEntryInfo) { foreach (var match in scoreEntryInfo.TeamMatchupWithMatches.Matches) { if (!IsMatchValid(match, scoreEntryInfo.Week.year.value)) { return(new string[] { "Must have valid score, points, and equitable score for all players in a match." }); } } return(new string[0]); }
public static IEnumerable <string> VerifyTotalPoints(ScoreEntryInfo scoreEntryInfo) { bool greaterThan24Error = false; bool mustBe24Error = false; foreach (var match in scoreEntryInfo.TeamMatchupWithMatches.Matches) { if (!IsMatchValid(match, scoreEntryInfo.Week.year.value)) { // other validators will take care of messaging. continue; } // don't try to add points if the results don't contain scores. if (!(ResultContainScores(match.Result1) && ResultContainScores(match.Result2))) { continue; } if (match.Result1.Points + match.Result2.Points > 24) { greaterThan24Error = true; } bool canBeLessThan24 = false; if (match.Result1.PlayerId < 3 || match.Result2.PlayerId < 3) { canBeLessThan24 = true; } if (match.Result1.Points + match.Result2.Points < 24 && !canBeLessThan24) { mustBe24Error = true; } } List <string> errors = new List <string>(2); if (mustBe24Error) { errors.Add("When neither player is a sub/no show, total points for a match must equal 24."); } if (greaterThan24Error) { errors.Add("Total points in a match can not be greater than 24."); } return(errors); }
public static IEnumerable <string> CheckEquitableScores(ScoreEntryInfo scoreEntryInfo) { foreach (var match in scoreEntryInfo.TeamMatchupWithMatches.Matches) { bool error = !VerifyEquitableScore(match.Result1) || !VerifyEquitableScore(match.Result2); if (error) { return(new List <string> { "Equitable scores must be less than or equal to scores." }); } } return(new string[0]); }
private void Validate() { // Don't do any validation if there are no matches or proposed matches to validate! if (this.teamMatchupWithMatches.Matches == null || this.teamMatchupWithMatches.Matches.Count() == 0) { this.IsValid = true; return; } // TODO: need two new validators still // 1. need a validator that makes sure a player hasn't already played this week in another matchup // 2. need to validate that a requested player is even in the requested year. IEnumerable <ScoreEntryValidators.ScoreValidator> scoreValidators = new List <ScoreEntryValidators.ScoreValidator> { ScoreEntryValidators.DuplicatePlayerValidator, ScoreEntryValidators.VerifyTotalPoints, ScoreEntryValidators.VerifyMatchComplete, ScoreEntryValidators.CheckEquitableScores, }; var scoreEntryInfo = new ScoreEntryInfo { TeamMatchupWithMatches = this.teamMatchupWithMatches, Week = this.week }; foreach (var sv in scoreValidators) { var validatorErrors = sv(scoreEntryInfo); if (validatorErrors != null) { this.Errors.AddRange(validatorErrors); } } this.IsValid = this.Errors.Count == 0; }