public IHttpActionResult CreateMovie(MovieDtos movieDto) { if (!ModelState.IsValid) { return(BadRequest()); } var movie = Mapper.Map <MovieDtos, Movie>(movieDto); _context.Movies.Add(movie); _context.SaveChanges(); movieDto.Id = movie.Id; return(Created(new Uri(Request.RequestUri + "/" + movie.Id), movieDto)); }
public void UpdateMovie(int id, MovieDtos movieDto) { var MovieInDb = _context.Movies.SingleOrDefault(m => m.Id == id); if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } if (MovieInDb == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } Mapper.Map(movieDto, MovieInDb); }
public void UpdateMovie(int id, MovieDtos movieDto) { //When submitting the form, if you have an error in the date, ModelState.IsValid will be false if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadGateway); } var movieInDb = _context.Movie.SingleOrDefault(c => c.Id == id); if (movieInDb == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } Mapper.Map <MovieDtos, Movie>(movieDto, movieInDb); _context.SaveChanges(); }
public void PutMovie(int id, MovieDtos movieDto) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadGateway); } var movieInDb = _context.Movies.SingleOrDefault(m => m.Id == id); if (movieInDb == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } Mapper.Map(movieDto, movieInDb); _context.SaveChanges(); }
public IHttpActionResult UpdateMovie(int id, MovieDtos movieDtos) { if (!ModelState.IsValid) { return(BadRequest()); } var movieInDb = _context.Movies.FirstOrDefault(m => m.Id == id); if (movieInDb == null) { return(NotFound()); } Mapper.Map(movieDtos, movieInDb); return(Ok(_context.SaveChanges())); }