public IHttpActionResult PutMovie(Movie movie) { if (!ModelState.IsValid) { return BadRequest(ModelState); } movieRepository.Update(movie); return StatusCode(HttpStatusCode.OK); }
public IHttpActionResult PostMovie(Movie movie) { if (!ModelState.IsValid) { return BadRequest(ModelState); } movieRepository.Add(movie); return CreatedAtRoute("DefaultApi", new { id = movie.Id }, movie); }
public void Test_Add_ListAll() { Movie mov = new Movie() { Id = 20, Title = "Avengers: Age Of Ultron", Genre = new Genre() { Id = 2, Name = "Action" }, Price = 150, Year = DateTime.Now.Date, ImgUrl = "http://scaled.ysimag.es/movie/the-avengers-age-of-ultron", TrailerUrl = "https://www.youtube.com/watch?v=S2HIda5wSVU" }; mov.Id = 1; mov.Title = "Alice in Wonderland"; mov.Genre.Id = 2; mov.Genre.Name = "Action"; mov.Price = 150; mov.ImgUrl = "http://scaled.ysimag.es/movie/the-avengers-age-of-ultron"; mov.TrailerUrl = "https://www.youtube.com/watch?v=S2HIda5wSVU"; mov.Year = DateTime.Now.Date; MovieRepository repository = new MovieRepository(); int numberOfMovies = repository.GetAll().Count(); Movie result = repository.Add(mov); Assert.NotNull(result); int finalNumberOfMovies = repository.GetAll().Count(); Assert.AreEqual(numberOfMovies + 1, finalNumberOfMovies); }