Exemplo n.º 1
0
        public async Task <MovieDtoResult> Post(MovieDtoCreate movie)
        {
            var model  = _mapper.Map <MovieModel>(movie);
            var entity = _mapper.Map <MovieEntity>(model);
            var result = await _repository.InsertAsync(entity);

            return(_mapper.Map <MovieDtoResult>(result));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Post([FromBody] MovieDtoCreate movie)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                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));
            }
        }