public MoveiDto PostMovie(MoveiDto MoveiDto) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.NotFound); } var movie = mapper.Map <MoveiDto, Movie>(MoveiDto); db.Movies.Add(movie); try { db.SaveChanges(); } catch { throw new HttpResponseException(HttpStatusCode.NotFound); } MoveiDto.Id = movie.Id; return(MoveiDto); }
public void PutMovie(int id, MoveiDto MoveiDto) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var movie = mapper.Map <MoveiDto, Movie>(MoveiDto); if (id != movie.Id) { throw new HttpResponseException(HttpStatusCode.BadRequest); } db.Entry(movie).State = EntityState.Modified; try { db.SaveChanges(); } catch { throw new HttpResponseException(HttpStatusCode.BadRequest); } }