public async Task <ElectionDtoCreateResult> Post(ElectionDtoCreate election) { var model = _mapper.Map <ElectionModel>(election); var entity = _mapper.Map <ElectionEntity>(model); var result = await _repository.InsertAsync(entity); return(_mapper.Map <ElectionDtoCreateResult>(result)); }
public async Task <ActionResult> Post([FromBody] ElectionDtoCreate election) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var result = await _service.Post(election); if (result != null) { return(Created(new Uri(Url.Link("GetElectionWithId", new { id = result.Id })), result)); } else { return(BadRequest()); } } catch (ArgumentException e) { return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message)); } }