Exemple #1
0
 public Movie(MovieWriteDTO model, Genre genre)
 {
     Title           = model.Title;
     Genre           = genre;
     NumberInStock   = model.NumberInStock;
     DailyRentalRate = model.DailyRentalRate;
 }
        public async Task <ActionResult <Movie> > Post(MovieWriteDTO model)
        {
            var genre = await _genreRepository.Get(model.GenreId);

            if (genre == null)
            {
                return(BadRequest("No genre found with the given id"));
            }

            var movie = new Movie(model, genre);

            await _repository.Add(movie);

            return(movie);
        }
        public async Task <ActionResult <Movie> > Put(string id, MovieWriteDTO model)
        {
            var genre = await _genreRepository.Get(model.GenreId);

            if (genre == null)
            {
                return(BadRequest("No genre found with the given id"));
            }

            var movie = new Movie(model, genre);

            await _repository.Update(id, movie);

            movie = await _repository.Get(id);

            if (movie == null)
            {
                return(NotFound("No movie found with the given id"));
            }

            return(Ok(movie));
        }