예제 #1
0
        public async Task <ActionResult <ProducerDTO> > PostProducer(ProducerDTO producerDTO)
        {
            Country country = await _context.Countries.FindAsync(producerDTO.CountryId);

            Producer producer = new Producer
            {
                CompanyName           = producerDTO.CompanyName,
                YearEstablished       = producerDTO.YearEstablished,
                EstimatedCompanyValue = producerDTO.EstimatedCompanyValue,
                Country = country
            };


            _context.Producers.Add(producer);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetProducer), new { id = producerDTO.Id }, producerDTO));
        }
예제 #2
0
        public async Task <ActionResult <MovieDTO> > PostMovie(MovieDTO movieDTO)
        {
            Person director = await _context.People.FindAsync(movieDTO.DirectorId);

            Country country = await _context.Countries.FindAsync(movieDTO.CountryId);

            Movie movie = new Movie
            {
                Title    = movieDTO.Title,
                Director = director,
                Genre    = movieDTO.Genre,
                Length   = movieDTO.Length,
                Year     = movieDTO.Year,
                Country  = country
            };

            await AddActorsToMovie(movieDTO, movie);
            await AddProducersToMovie(movieDTO, movie);

            _context.Movies.Add(movie);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetMovie), new { id = movieDTO.Id }, movieDTO));
        }