Esempio n. 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());
        }
Esempio n. 2
0
        public async Task <ValidatorResult> Validate(EndSubmissions 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.InProgress)
            {
                return(new ValidatorResult(ValidatorErrors.Games.InvalidGameRoundStatus));
            }

            var isOwnerResult = await gameOrRoundOwnerRule.Validate(request);

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

            var numberOfAnswers = await playerAnswersRepository.GetNumberOfAnswers(request.GameRoundId);

            if (numberOfAnswers < GameConstants.MinimumAnswersCount)
            {
                return(new ValidatorResult(ValidatorErrors.Games.NotEnoughSubmittedAnswers));
            }

            return(new ValidatorResult());
        }
Esempio n. 3
0
        public async Task <ValidatorResult> Validate(SkipRound request)
        {
            var baseResult = await baseGameRequestsValidator.Validate(request);

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

            var isOwnerResult = await gameOrRoundOwnerRule.Validate(request);

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

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

            if (!round.IsActive || !statuses.Contains(round.Status))
            {
                return(new ValidatorResult(ValidatorErrors.Games.InvalidGameRoundStatus));
            }

            return(new ValidatorResult());
        }