public void Remove(Movie movie) { using (var ctx = new MovieShopContext()) { var movieToDelete = ctx.Movies.FirstOrDefault(x => x.Id == movie.Id); ctx.Movies.Remove(movieToDelete); ctx.SaveChanges(); } }
public void orderline_properties_set_test() { OrderLineViewModel line = new OrderLineViewModel(); var movie = new Movie() { Id = 1, Title = "The Ring", Price = 200 }; line.Movie = movie; line.Amount = 10; Assert.AreEqual(line.Movie, movie, "Movies are the same"); Assert.AreEqual(line.Amount, 10, "Movie amount is wrong"); }
public void Add(Movie movie) { using (var ctx = new MovieShopContext()) { // create queries ctx.Movies.Add(movie); // execute changes ctx.SaveChanges(); } }
public Movie Delete(Movie movie) { using (var ctx = new MovieShopContextDB()) { var movieDB = ctx.Movies.FirstOrDefault(item => item.Id == movie.Id); ctx.Movies.Remove(movieDB); ctx.SaveChanges(); return movie; } }
public void Orderline_Properties_Set_Test() { OrderLine line = new OrderLine(); var movie = new Movie() { Id = 1, Title = "Smurf" }; line.Movie = movie; line.Amount = 10; Assert.AreEqual(line.Movie, movie, "My movie should be the same"); Assert.AreEqual(line.Amount, 10, "Amount should be 10"); }
public ActionResult Create(Movie movie) { if (ModelState.IsValid) { movie.Genre = facade.GetGenreRepository().Read(movie.Genre.Id); facade.GetMovieRepository().Add(movie); return Redirect("Index"); } return View(movie); }
public Movie Add(Movie movie) { using (var ctx = new MovieShopContextDB()) { ctx.Genres.Attach(movie.Genre); //Create the queries ctx.Movies.Add(movie); //Execute the queries ctx.SaveChanges(); return movie; } }
public void Add_multi_genre_to_movie_added_in_db() { Movie movie = new Movie() { Title = "Svend the rich", Price=222, Year = DateTime.Now}; List<Genre> genres = new List<Genre>(); List<Genre> genresFound = facade.GetGenresRepository().ReadAll(); genres.Add(genresFound[0]); genres.Add(genresFound[2]); movie.Genres = genres; facade.GetMovieRepository().Add(movie); List<Genre> genresFound2 = facade.GetGenresRepository().ReadAll(); List<Movie> movies = facade.GetMovieRepository().ReadAll(); }
public Movie Update(Movie movie) { using (var ctx = new MovieShopContextDB()) { var movieDB = ctx.Movies.FirstOrDefault(item => item.Id == movie.Id); movieDB.Genre = ctx.Genres.FirstOrDefault(item => item.Id == movie.Genre.Id); movieDB.imageURL = movie.imageURL; movieDB.Price = movie.Price; movieDB.Title = movie.Title; movieDB.trailerURL = movie.trailerURL; movieDB.Year = movie.Year; ctx.SaveChanges(); return movie; } }
public void Update(Movie movie) { using (var ctx = new MovieShopContext()) { var movieToUpdate = ctx.Movies.FirstOrDefault(x => x.Id == movie.Id); if (movieToUpdate != null) { movieToUpdate.Title = movie.Title; movieToUpdate.Price = movie.Price; movieToUpdate.Year = movie.Year; movieToUpdate.PicturePath = movie.PicturePath; movieToUpdate.TrailerURL = movie.TrailerURL; movieToUpdate.Genre = ctx.Genres.FirstOrDefault(x => x.Id == movie.Genre.Id); ctx.SaveChanges(); } } }
public Movie Add(Movie movie) { if (movie.Genres != null) { //movie.Genres.ForEach(x => ctx.Genres.Attach(x)); // -------- or like below for more code lines //foreach (var item in movie.Genres) //{ // ctx.Genres.Attach(item); //} // -------- to here!!! } //Create the queries ctx.Movies.Add(movie); //Execute the queries ctx.SaveChanges(); return movie; }
public Movie Remove(Movie movieToRemove) { var removed = ctx.Movies.Remove(movieToRemove); ctx.SaveChanges(); return removed; }
public void Movie_is_in_db_after_add() { Movie movie = new Movie() {Id = -1, Title = "Svend the rich", Price = 222, Year = DateTime.Now }; List<Genre> genres = new List<Genre>(); List<Genre> genresFound = facade.GetGenresRepository().ReadAll(); genres.Add(genresFound[0]); genres.Add(genresFound[2]); movie.Genres = genres; Movie movieAdded = facade.GetMovieRepository().Add(movie); Assert.IsTrue(movieAdded.Id != -1); Movie movieAddedReturned = facade.GetMovieRepository().Read(movieAdded.Id); Assert.AreSame(movieAdded, movieAddedReturned); }
public ActionResult Update(Movie Movie) { Movie.Genre = facade.GetGenreRepository().Read(Movie.Genre.Id); facade.GetMovieRepository().Update(Movie); return Redirect("~/Movies/Index"); }
public ActionResult Delete(Movie movie) { facade.GetMovieRepository().Delete(movie); return Redirect("~/Movies/Index"); }
public ActionResult Create(Movie movie) { movie.Genre = facade.GetGenreRepository().ReadById(movie.Genre.Id); facade.GetMovieRepository().Add(movie); return Redirect("Index"); }
public ActionResult Edit(Movie movie) { facade.GetMovieRepository().Update(movie); return Redirect("Index"); }
static void Main(string[] args) { Movie movie = new Movie() { Id = 2, Price = 200d, Title = "Lego movie 2", Year = DateTime.Now.AddYears(-1) }; Facade facade = new Facade(); facade.GetMovieRepository().Add(movie); }
public Movie Update(Movie movie) { Movie movieUpdated = ctx.Movies.Attach(movie); ctx.SaveChanges(); return movieUpdated; }