// Get /api/movies/1 public IHttpActionResult GetMovie(int id) { var movieDto = MovieDto.Mapper(_db.Movies.SingleOrDefault(m => m.Id == id), new MovieDto()); if (movieDto == null) { return(NotFound()); } return(Ok(movieDto)); }
// GET /api/movies public IHttpActionResult GetMovies() { var moviesDto = new List <MovieDto>(); foreach (var movie in _db.Movies) { var movieDto = new MovieDto(); MovieDto.Mapper(movie, movieDto); moviesDto.Add(movieDto); Debug.WriteLine($"{movieDto.Id}: {movieDto.Name}"); } return(Ok(moviesDto)); }
public IHttpActionResult PostMovie(MovieDto movieDto) { if (!ModelState.IsValid) { return(BadRequest()); } var dbMovie = _db.Movies.Add((Movie)MovieDto.Mapper(movieDto, new Movie())); _db.SaveChanges(); movieDto.Id = dbMovie.Id; return(Created($"{Request.RequestUri}/{movieDto.Id}", movieDto)); }
public IHttpActionResult PutMovie(MovieDto movieDto) { if (!ModelState.IsValid) { return(BadRequest()); } var dbMovie = _db.Movies.SingleOrDefault(m => m.Id == movieDto.Id); if (dbMovie == null) { return(NotFound()); } MovieDto.Mapper(movieDto, dbMovie); _db.SaveChanges(); return(Ok(movieDto)); }