예제 #1
0
 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();
     }
 }
예제 #2
0
        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");
        }
예제 #3
0
 public void Add(Movie movie)
 {
     using (var ctx = new MovieShopContext())
     {
         // create queries
         ctx.Movies.Add(movie);
         // execute changes
         ctx.SaveChanges();
     }
 }
예제 #4
0
 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;
     }
 }
예제 #5
0
        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");
        }
예제 #6
0
        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);
        }
예제 #7
0
 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;
     }
 }
예제 #8
0
        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();
        }
예제 #9
0
 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;
     }
 }
예제 #10
0
 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();
         }
     }
 }
예제 #11
0
        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;
        }
예제 #12
0
 public Movie Remove(Movie movieToRemove)
 {
     var removed = ctx.Movies.Remove(movieToRemove);
     ctx.SaveChanges();
     return removed;
 }
예제 #13
0
        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);
        }
예제 #14
0
 public ActionResult Update(Movie Movie)
 {
     Movie.Genre = facade.GetGenreRepository().Read(Movie.Genre.Id);
     facade.GetMovieRepository().Update(Movie);
     return Redirect("~/Movies/Index");
 }
예제 #15
0
 public ActionResult Delete(Movie movie)
 {
     facade.GetMovieRepository().Delete(movie);
     return Redirect("~/Movies/Index");
 }
예제 #16
0
 public ActionResult Create(Movie movie)
 {
     movie.Genre = facade.GetGenreRepository().ReadById(movie.Genre.Id);
     facade.GetMovieRepository().Add(movie);
     return Redirect("Index");
 }
예제 #17
0
 public ActionResult Edit(Movie movie)
 {
     facade.GetMovieRepository().Update(movie);
     return Redirect("Index");
 }
예제 #18
0
 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);
 }
예제 #19
0
 public Movie Update(Movie movie)
 {
     Movie movieUpdated = ctx.Movies.Attach(movie);
     ctx.SaveChanges();
     return movieUpdated;
 }