コード例 #1
0
 public IActionResult Create([FromBody] CreateLotteryDrawCommand lotteryDrawCommand)
 {
     try
     {
         _lotteryService.CreateDraw(lotteryDrawCommand);
         return(new OkResult());
     }
     catch (Exception ex)
     {
         return(new BadRequestObjectResult(ex.Message));
     }
 }
コード例 #2
0
        public void CreateDraw(CreateLotteryDrawCommand lotteryDrawCommand)
        {
            var existingDraw = _repository.FindByName(lotteryDrawCommand.Name);

            if (existingDraw != null)
            {
                throw new ArgumentException($"Lottery draw {lotteryDrawCommand.Name} already exists");
            }

            Domain.LotteryDraw draw = new Domain.LotteryDraw(lotteryDrawCommand.Name,
                                                             lotteryDrawCommand.Description,
                                                             lotteryDrawCommand.DrawDate.Date,
                                                             new Domain.LotteryNumbers(_primaryNumberCount, _totalAmountOfPrimaryNumbers),
                                                             new Domain.LotteryNumbers(_secondaryNumberCount, _totalAmountOfSecondaryNumbers));
            _repository.Create(draw);
        }