public ActionResult CreateMovie(MovieDto movieDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            //var movie = new Movie
            //{
            //    Name = movieDto.Name,
            //    GenreId = movieDto.GenreId,
            //    DateAdded = DateTime.Now,
            //    ReleaseDate = movieDto.ReleaseDate,
            //    NumberInStock = movieDto.NumberInStock

            //};
            var movie = new Movie();

            movie = _mapper.Map(movieDto, movie);


            movie.DateAdded = DateTime.Now;
            _context.Movies.Add(movie);
            _context.SaveChanges();
            movieDto.Id = movie.Id;

            return(Ok(movieDto));
        }
Пример #2
0
        public ActionResult CreateBook(AudioBookDto audioBookDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            //var movie = new Movie
            //{
            //    Name = movieDto.Name,
            //    GenreId = movieDto.GenreId,
            //    DateAdded = DateTime.Now,
            //    ReleaseDate = movieDto.ReleaseDate,
            //    NumberInStock = movieDto.NumberInStock

            //};
            var audioBook = new AudioBook();

            audioBook = _mapper.Map(audioBookDto, audioBook);

            audioBookDto.Id = audioBook.Id;

            _context.AudioBooks.Add(audioBook);
            _context.SaveChanges();

            return(Ok(audioBookDto));
        }