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")); }
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)); }
public CreateVoterCommand(VoterForCreationDto voterForCreationDto) { _voterForCreationDto = voterForCreationDto; }