Beispiel #1
0
        public async Task <IActionResult> PutMovie(int id, MovieBinder movie)
        {
            Movie m = new Movie();

            m.id          = movie.id;
            m.releaseDate = movie.releaseDate;
            m.title       = movie.title;

            m.director = await _context.Directors.FindAsync(movie.directorId);

            if (id != movie.id)
            {
                return(BadRequest());
            }

            _context.Entry(m).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MovieExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
Beispiel #2
0
        public async Task <ActionResult <Movie> > PostMovie(MovieBinder movie)
        {
            //Director m = _context.Directors.Find(dir);
            //movie.director = m;

            Movie m = new Movie();

            m.title       = movie.title;
            m.releaseDate = movie.releaseDate;
            m.director    = _context.Directors.Find(movie.directorId);

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

            return(CreatedAtAction("GetMovie", new { id = m.id }, m));
        }