public UsersController(StatlerAndWaldorfContext context)
 {
     _context = context;
 }
Exemplo n.º 2
0
 public MoviesController(StatlerAndWaldorfContext context)
 {
     _context = context;
 }
 public StatlerAndWaldorf(StatlerAndWaldorfContext context)
 {
     _context = context;
 }
Exemplo n.º 4
0
        public static void Initialize(StatlerAndWaldorfContext context)
        {
            context.Database.EnsureCreated();

            // Look for any students.
            if (context.Users.Any())
            {
                return;   // DB has been seeded
            }

            byte[] passwordBytes = Encoding.ASCII.GetBytes("123456");
            var    md5           = new MD5CryptoServiceProvider();

            byte[] md5data      = md5.ComputeHash(passwordBytes);
            string passwordHash = Encoding.ASCII.GetString(md5data);

            var users = new Users[]
            {
                new Users {
                    Id = 1, email = "*****@*****.**", firstName = "Ariel", lastName = "Barak", passwordHash = passwordHash, admin = true, country = "Israel"
                },
                new Users {
                    Id = 2, email = "a@a", firstName = "a", lastName = "b", passwordHash = passwordHash, admin = false, country = "Israel"
                }
            };

            foreach (Users u in users)
            {
                context.Users.Add(u);
            }
            context.SaveChanges();

            DateTime date = new DateTime(2016, 05, 23); //new date for movie creation

            Reviews review = new Reviews()              //new review, without movie
            {
                review    = "The movie really was adorable! I knew exactly what to expect since I read the book, but I loved the adaptation. What helps the movie most is that the novelist, Jojo Moyees, wrote her own screenplay.She did a great job transitioning the story from paper to screen.Little things that were left out of the novel werent really needed to move the story along. Both Emilia Clarke and Sam Clafin were excellent. Her facial expressions were amazing and her insane eyebrows deserve some type of award all on their own.",
                isBlocked = false,
                userId    = 2,
                userName  = users[1].firstName + " " + users[1].lastName
            };

            Movies movie = new Movies//new movie
            {
                Title       = "Me Before You",
                Genre       = "Drama",
                Length      = 111,
                ReleaseDate = date
            };

            review.movieId = movie.Id;
            movie.Reviews.Add(review);

            var movies = new Movies[]
            {
                movie
            };

            foreach (Movies m in movies)
            {
                context.Movies.Add(m);
            }
            context.SaveChanges();

            var reviews = new Reviews[]
            {
                review
            };

            foreach (Reviews r in reviews)
            {
                context.Reviews.Add(r);
            }
            context.SaveChanges();
        }