public IActionResult UpdateMovies(MoviesViewModel model) { if (ModelState.IsValid) { var movie = _context.Movies.Single(x => x.MovieID == staticID); //Can't use shorter method to do in one line, because ID is not being changed _context.Entry(movie).Property(x => x.Category).CurrentValue = model.MoviesModel.Category; _context.Entry(movie).Property(x => x.Title).CurrentValue = model.MoviesModel.Title; _context.Entry(movie).Property(x => x.Year).CurrentValue = model.MoviesModel.Year; _context.Entry(movie).Property(x => x.Director).CurrentValue = model.MoviesModel.Director; _context.Entry(movie).Property(x => x.Rating).CurrentValue = model.MoviesModel.Rating; _context.Entry(movie).Property(x => x.Edited).CurrentValue = model.MoviesModel.Edited; _context.Entry(movie).Property(x => x.LentTo).CurrentValue = model.MoviesModel.LentTo; _context.Entry(movie).Property(x => x.Notes).CurrentValue = model.MoviesModel.Notes; _context.SaveChanges(); return(RedirectToAction("ViewMovies")); } else { return(View(new MoviesViewModel { MoviesModel = _context.Movies.Single(x => x.MovieID == staticID), //single allows casting an IQueryable query that will end in one result becoming a model ID = staticID })); } }
public async Task <IActionResult> PutTopRatedMovies1Model(int id, TopRatedMovies1 topRatedMovies1Model) { if (id != topRatedMovies1Model.id) { return(BadRequest()); } _context.Entry(topRatedMovies1Model).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TopRatedMovies1ModelExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutMovie(int id, [FromBody] Movie movie) { if (!MovieExists(id)) { return(BadRequest()); } movie.ID = id; _context.Entry(movie).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieExists(id)) { return(NotFound()); } else { throw; } } return(CreatedAtAction("GetMovie", new { id = movie.ID }, movie)); }
public async Task <IActionResult> PutMovie(int id, Movie movie) { if (id != movie.MovieID) { return(BadRequest()); } _context.Entry(movie).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit([Bind(Include = "ID,Title,Director,Date")] MovieDB movieDB) { if (ModelState.IsValid) { db.Entry(movieDB).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(movieDB)); }
public ActionResult Edit([Bind(Include = "ID,Title,Year,Lenght,Director,Genre")] Movie movie) { if (ModelState.IsValid) { movie.UserId = User.Identity.GetUserId(); db.Entry(movie).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(RedirectToAction("Index", "Home")); }