Exemple #1
0
        public async Task <IActionResult> CreateLottery(CreateLotteryRequest request)
        {
            CreateLotteryResponse response = await _lotteryService.CreateLotteryAsync(request);

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

            return(BadRequest(response.GetErrors()));
        }
Exemple #2
0
        public async Task <CreateLotteryResponse> CreateLotteryAsync(CreateLotteryRequest request)
        {
            CreateLotteryResponse response = new CreateLotteryResponse();

            // Validate Lottery
            Lottery          lottery         = new Lottery(request.Price, request.StartDateBet, request.EndDateBet, request.LotteryDateBet);
            LotteryValidator ticketValidator = new LotteryValidator();
            ValidationResult ticketResult    = await ticketValidator.ValidateAsync(lottery);

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

            await _lotteryRepository.CreateAsync(lottery);

            return(response);
        }