public IActionResult Create([FromBody] CreateLotteryDrawCommand lotteryDrawCommand) { try { _lotteryService.CreateDraw(lotteryDrawCommand); return(new OkResult()); } catch (Exception ex) { return(new BadRequestObjectResult(ex.Message)); } }
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); }