public void SaveMovie(Movie movie)
 {
     if (movie.MovieId == 0)
     {
         context.Movies.Add(movie);
     }
     else
     {
         Movie dbEntry = context.Movies
                         .FirstOrDefault(m => m.MovieId == movie.MovieId);
         if (dbEntry != null)
         {
             dbEntry.MovieName   = movie.MovieName;
             dbEntry.Rating      = movie.Rating;
             dbEntry.ReleaseDate = movie.ReleaseDate;
             dbEntry.User        = movie.User;
             dbEntry.ImageUrl    = movie.ImageUrl;
             dbEntry.Genre       = movie.Genre;
             dbEntry.Description = movie.Description;
         }
     }
     context.SaveChanges();
 }
 public void SaveUser(User user)
 {
     if (user.UserId == 0)
     {
         context.Users.Add(user);
     }
     else
     {
         User dbEntry = context.Users
                        .FirstOrDefault(u => u.UserId == user.UserId);
         if (dbEntry != null)
         {
             dbEntry.Email           = user.Email;
             dbEntry.Password        = user.Password;
             dbEntry.ConfirmPassword = user.ConfirmPassword;
         }
     }
     context.SaveChanges();
 }
示例#3
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MovieAppDbContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <MovieAppDbContext> >()))
            {
                // Look for any movies.
                if (context.Movies.Any())
                {
                    return;   // DB has been seeded
                }

                context.Movies.AddRange(
                    new Movie
                {
                    MovieName   = "When Harry Met Sally",
                    ReleaseDate = DateTime.Parse("1989-2-12"),
                    Genre       = Genre.COMEDY,
                    Rating      = 3,
                    Description = "this is the description",
                    ImageUrl    = "https://upload.wikimedia.org/wikipedia/en/3/38/The_SpongeBob_Movie_Sponge_on_the_Run.jpg"
                },

                    new Movie
                {
                    MovieName   = "Ghostbusters ",
                    ReleaseDate = DateTime.Parse("1984-3-13"),
                    Genre       = Genre.HORROR,
                    Rating      = 4,
                    Description = "This is really scary kids movie",
                    ImageUrl    = "https://upload.wikimedia.org/wikipedia/en/2/2f/Ghostbusters_%281984%29_theatrical_poster.png"
                },

                    new Movie
                {
                    MovieName   = "Ghostbusters 2",
                    ReleaseDate = DateTime.Parse("1986-2-23"),
                    Genre       = Genre.HORROR,
                    Rating      = 3,
                    Description = "This is a horror movie",
                    ImageUrl    = "https://upload.wikimedia.org/wikipedia/en/0/01/Ghostbusters_ii_poster.jpg"
                },

                    new Movie
                {
                    MovieName   = "Rio Bravo",
                    ReleaseDate = DateTime.Parse("1959-4-15"),
                    Genre       = Genre.THRILLER,
                    Rating      = 4,
                    Description = "This is athriller movie",
                    ImageUrl    = "https://images-na.ssl-images-amazon.com/images/I/51I9qHhm1AL._AC_.jpg"
                }
                    );;
                context.SaveChanges();
                // Look for any movies.
                if (context.Users.Any())
                {
                    return;   // DB has been seeded
                }

                context.Users.AddRange(
                    new User
                {
                    Email           = "*****@*****.**",
                    Password        = "******",
                    ConfirmPassword = "******"
                },

                    new User
                {
                    Email           = "*****@*****.**",
                    Password        = "******",
                    ConfirmPassword = "******"
                }
                    );
                context.SaveChanges();
            }
        }