예제 #1
0
        public async Task <IActionResult> AddVoter(VoterForCreationDto voterForCreationDto)
        {
            var voterToCreate = _mapper.Map <Voter> (voterForCreationDto);

            _repo.Add(voterToCreate);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("Could not add voter"));
        }
예제 #2
0
        public async Task <IActionResult> CreateVoter(VoterForCreationDto voterForCreationDto)
        {
            var validateVoter = voterForCreationDto.ValidateVoter();

            if (validateVoter.Any())
            {
                return(ValidationProblem(validateVoter.First()));
            }

            var voterFromCommandHandler = await Mediator.Send(new CreateVoterCommand(voterForCreationDto));

            return(CreatedAtRoute(
                       new { voterId = voterFromCommandHandler.Id },
                       voterFromCommandHandler));
        }
예제 #3
0
 public CreateVoterCommand(VoterForCreationDto voterForCreationDto)
 {
     _voterForCreationDto = voterForCreationDto;
 }