public async Task <ActionResult> Post([FromBody] MovieDTOCreate movie) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var result = await _service.Post(movie); if (result != null) { return(Created( new Uri( Url.Link("GetWithId", new { id = result.Id } )), result)); } else { return(BadRequest()); } } catch (ArgumentException ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); } }
public async Task <MovieDTO> Post(MovieDTOCreate movie) { var model = _mapper.Map <MovieModel>(movie); var entity = _mapper.Map <MovieEntity>(model); var result = await _repository.InsertAsync(entity); return(_mapper.Map <MovieDTO>(result)); }