Esempio n. 1
0
        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));
            }
        }
Esempio n. 2
0
        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));
        }