Exemple #1
0
 public CreateSeasonValidator(ILeagueRepository repo)
 {
     _repo = repo;
     RuleFor(x => x).MustAsync(async(cmd, tok) =>
     {
         var league = await _repo.GetAsync(cmd.LeagueId);
         if (league == null)
         {
             return(false);
         }
         return(true);
         //return league.Teams.UniqueNameAbbr(cmd);
     });
 }
Exemple #2
0
        // is this testable. is there leakage
        // if we put the check LeagueId inside the validator, then it must be async - undesirable
        public async Task <ValidationResult> AddTeam(AddTeamCommand cmd)
        {
            var league = await _repo.GetAsync(cmd.LeagueId);

            if (league == null)
            {
                return(new ValidationResult(new[] { new ValidationFailure(nameof(cmd.LeagueId), $"League {cmd.LeagueId} not found") }));
            }
            var validator = new AddTeamValidator(league);
            var result    = validator.Validate(cmd);

            if (result.IsValid)
            {
                //var team = await _repo.CreateTeam(cmd);
                //the teamId has to be globally unique, and MUST come from the repository
                var team = Team.New(league, 0, cmd.Name, cmd.Abbr);
                league.AddTeam(team);
            }
            return(result);
        }