Exemple #1
0
        public async Task <ValidatorResult> Validate(StartGameRound request)
        {
            var baseResult = await baseGameRequestsValidator.Validate(request);

            if (!baseResult.IsSuccessful)
            {
                return(new ValidatorResult(baseResult.Error));
            }

            var round = await gameRoundsRepository.GetGameRound(request.GameId, request.GameRoundId);

            if (round.Status != Common.Enums.GameRoundStatusEnum.Pending)
            {
                return(new ValidatorResult(ValidatorErrors.Games.InvalidGameRoundStatus));
            }

            var isOwnerResult = await gameOrRoundOwnerRule.Validate(request);

            if (!isOwnerResult.IsSuccessful)
            {
                return(new ValidatorResult(isOwnerResult.Error));
            }

            var playerCount = await playersRepository.GetActivePlayersCount(request.GameId);

            if (playerCount < GameConstants.MinimumPlayersCount)
            {
                return(new ValidatorResult(ValidatorErrors.Games.NotEnoughPlayers));
            }

            return(new ValidatorResult());
        }