public IHttpActionResult PutMovie(int id, Movie movie) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != movie.ID) { return(BadRequest()); } db.Entry(movie).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!MovieExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "ID,Title,ReleaseDate,Genre,Price")] Movie movie) { if (ModelState.IsValid) { _db.Movies.Add(movie); _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(movie)); }
public ActionResult Create([Bind(Include = "MovieId,Title,YearReleased")] Movie movie) { if (ModelState.IsValid) { db.Movies.Add(movie); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(movie)); }
public ActionResult DeleteConfirmed(int id) { Order order = db.Orders.Find(id); db.Orders.Remove(order); db.SaveChanges(); return(RedirectToAction("Index")); }
protected override void InnerHandle(EditMoviesTransition message) { var movies = message.Movies; foreach (var movie in movies) { var existing = _db.Movies.FirstOrDefault(m => m.ID == movie.ID); if (existing == null) { continue; } existing.Title = movie.Title; existing.Genre = movie.Genre; existing.ReleaseDate = movie.ReleaseDate; existing.Price = movie.Price; existing.StarRating = movie.StarRating; } _db.SaveChanges(); }
public static void PopulateTestData(MovieStoreDbContext dbContext) { // Gêneros var genre1 = new Genre() { Name = "Ação", Status = GenreStatusEnum.Active }; var genre2 = new Genre() { Name = "Aventura", Status = GenreStatusEnum.Active }; var genre3 = new Genre() { Name = "Comédia", Status = GenreStatusEnum.Active }; var genre4 = new Genre() { Name = "Ficção Científica", Status = GenreStatusEnum.Active }; var genre5 = new Genre() { Name = "Musical", Status = GenreStatusEnum.Active }; dbContext.Genres.Add(genre1); dbContext.Genres.Add(genre2); dbContext.Genres.Add(genre3); dbContext.Genres.Add(genre4); dbContext.Genres.Add(genre5); // Filmes dbContext.Movies.Add(new Movie() { Name = "Vingadores Ultimato", Status = MovieStatusEnum.Active, GenreId = genre1.Id }); dbContext.Movies.Add(new Movie() { Name = "John Wick 3", Status = MovieStatusEnum.Active, GenreId = genre1.Id }); dbContext.Movies.Add(new Movie() { Name = "Toy Story 4", Status = MovieStatusEnum.Active, GenreId = genre2.Id }); dbContext.Movies.Add(new Movie() { Name = "Aladdin", Status = MovieStatusEnum.Active, GenreId = genre2.Id }); dbContext.Movies.Add(new Movie() { Name = "Parasita", Status = MovieStatusEnum.Active, GenreId = genre3.Id }); dbContext.Movies.Add(new Movie() { Name = "Star Wars: Episódio IX", Status = MovieStatusEnum.Active, GenreId = genre4.Id }); dbContext.Movies.Add(new Movie() { Name = "O Rei Leão", Status = MovieStatusEnum.Active, GenreId = genre5.Id }); dbContext.SaveChanges(); }
public void SaveChanges() { _movieStoreDbContext.SaveChanges(); }