Exemplo n.º 1
0
        public Movie Add(Movie movie)
        {
            Movie _movie = _context.Movies.Find(movie.id);

            if (_movie == null)
            {
                _context.Movies.Add(movie);
                _context.SaveChanges();
                return(movie);
            }
            else
            {
                throw new DuplicateMovieFoundException("This movie is already in your favorites");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Repository method to add  movie to the colleciton
        /// </summary>
        /// <param name="movie"></param>
        /// <returns></returns>
        public Movie AddMovie(Movie movie)
        {
            var movieExists = _context.Movies.Any(e => e.Id == movie.Id && e.UserId == movie.UserId);

            if (!movieExists)
            {
                _context.Movies.Add(movie);
                _context.SaveChanges();
                return(movie);
            }
            else
            {
                throw new ArgumentException("Movie with specified id already exists");
            }
        }
Exemplo n.º 3
0
        public DatabaseFixture()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: "MoviesDB")
                          .Options;

            dbContext = new MoviesDbContext(options);
            dbContext.Movies.Add(new Movie {
                Id = 10001, Name = "Avatar", Comments = string.Empty, PosterPath = "avatar.jpg", ReleaseDate = "12-10-2009", VoteCount = 12345, VoteAverage = 7.5, UserId = "user1"
            });
            dbContext.Movies.Add(new Movie {
                Id = 10002, Name = "Titanic", Comments = string.Empty, PosterPath = "titanic.jpg", ReleaseDate = "12-10-1997", VoteCount = 72345, VoteAverage = 7.8, UserId = "user1"
            });
            dbContext.Movies.Add(new Movie {
                Id = 10003, Name = "Jurassic Park", Comments = string.Empty, PosterPath = "jurassicpartk.jpg", ReleaseDate = "13-10-1993", VoteCount = 82345, VoteAverage = 7.9, UserId = "user1"
            });
            dbContext.SaveChanges();
        }
Exemplo n.º 4
0
        public DatabaseFixture()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: "MovieDB")
                          .Options;

            dbcontext = new MoviesDbContext(options);

            // Insert seed data into the database using one instance of the context
            dbcontext.Movies.Add(new Movie {
                id = 354440, name = "Superman", posterPath = "superman.jpg", releaseDate = "12-10-2012", comments = string.Empty, voteAverage = 7.8, voteCount = 980
            });
            dbcontext.Movies.Add(new Movie {
                id = 354441, name = "Anaconda", posterPath = "anaconda.jpg", releaseDate = "12-10-2012", comments = string.Empty, voteAverage = 8.0, voteCount = 1080
            });
            dbcontext.Movies.Add(new Movie {
                id = 354442, name = "Independence Day", posterPath = "spiderman.jpg", releaseDate = "12-10-2012", comments = string.Empty, voteAverage = 7.8, voteCount = 980
            });
            dbcontext.SaveChanges();
        }
        public DatabaseFixture()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: "MovieDB")
                          .Options;

            dbcontext = new MoviesDbContext(options);

            dbcontext.Movies.Add(new Movie {
                Id = 1, Name = "movie1", Comments = "comments1", PosterPath = "path1", ReleaseDate = "releaseDate1", VoteAverage = 5.00, VoteCount = 100
            });
            dbcontext.Movies.Add(new Movie {
                Id = 2, Name = "movie2", Comments = "comments2", PosterPath = "path2", ReleaseDate = "releaseDate2", VoteAverage = 6.00, VoteCount = 200
            });
            dbcontext.Movies.Add(new Movie {
                Id = 3, Name = "movie3", Comments = "comments3", PosterPath = "path3", ReleaseDate = "releaseDate3", VoteAverage = 7.00, VoteCount = 300
            });

            dbcontext.SaveChanges();
        }
Exemplo n.º 6
0
 //Adds a movie to the DB
 public void AddMovie(Movie movie)
 {
     _context.Movies.Add(movie);
     _context.SaveChanges();
 }