Ejemplo n.º 1
0
        public async Task <IActionResult> PutReviewItem([FromRoute] int id, [FromBody] ReviewItem reviewItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PutMovieItem([FromRoute] int id, [FromForm] string title, [FromForm] string genre, [FromForm] int rating, [FromForm] string description, [FromForm] string director)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var movieItem = await _context.MovieItem.FindAsync(id);

            if (movieItem == null)
            {
                return(NotFound());
            }
            movieItem.Title                 = title;
            movieItem.Genre                 = genre;
            movieItem.Rating                = rating;
            movieItem.Description           = description;
            movieItem.Director              = director;
            _context.Entry(movieItem).State = EntityState.Modified;

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

            return(NoContent());
        }