Exemplo n.º 1
0
        public async Task <IActionResult> InsertNumbersLotteryResult(NumberLotteryRequest request)
        {
            NumberLotteryResponse response = await _lotteryService.InsertNumbersLotteryResultAsync(request);

            if (response.IsValid())
            {
                return(Ok(response));
            }

            return(BadRequest(response.GetErrors()));
        }
Exemplo n.º 2
0
        public async Task <NumberLotteryResponse> InsertNumbersLotteryResultAsync(NumberLotteryRequest request)
        {
            NumberLotteryResponse response = new NumberLotteryResponse();

            Lottery lottery = await _lotteryRepository.FindLotteryAsync(request.LotteryId);

            if (lottery == null)
            {
                response.SetError(new ErrorResponse(string.Empty, Msg.LotteryNotFound));
                return(response);
            }

            if (request.Numbers.Count() != 15) // TODO: PEGAR DO CONFIG
            {
                response.SetError(new ErrorResponse("Number", Msg.LimiteLotteryResultInvalid));
                return(response);
            }

            // Binding numbers
            foreach (string item in request.Numbers)
            {
                LotteryNumberResult          number          = new LotteryNumberResult(item, request.LotteryId);
                LotteryNumberResultValidator numberValidator = new LotteryNumberResultValidator();
                ValidationResult             numberResult    = await numberValidator.ValidateAsync(number);

                if (!numberResult.IsValid)
                {
                    response.AddErrorValidationResult(numberResult);
                    return(response);
                }

                if (lottery.ListNumbersResult.Any(s => s.Number.Contains(item)))
                {
                    response.SetError(new ErrorResponse("Number", Msg.NumberBetDuplicated));
                    return(response);
                }

                lottery.SetNumberInListLottery(number);
            }

            _lotteryRepository.Update(lottery);

            return(response);
        }