public void SaveOrder(Order order)
 {
     context.AttachRange(order.Lines.Select(l => l.Movie));
     if (order.OrderId == 0)
     {
         context.Orders.Add(order);
     }
     context.SaveChanges();
 }
        public static void EnsurePopulated(IApplicationBuilder app)
        {
            MovieDbContext context = app.ApplicationServices
                                     .CreateScope().ServiceProvider.GetRequiredService <MovieDbContext>();

            if (context.Database.GetPendingMigrations().Any())
            {
                context.Database.Migrate();
            }

            if (!context.Movies.Any())
            {
                context.Movies.AddRange();
                context.SaveChanges();
            }
        }
        public static void EnsurePopulated(IApplicationBuilder app)
        {
            MovieDbContext context = app.ApplicationServices
                                     .CreateScope().ServiceProvider.GetRequiredService <MovieDbContext>();

            if (context.Database.GetPendingMigrations().Any())
            {
                context.Database.Migrate();
            }

            Genre genre = new Genre {
                Name = "action"
            };

            if (!context.Genres.Any())
            {
                context.Genres.AddRange(
                    new Genre
                {
                    Name = "Action"
                },
                    new Genre
                {
                    Name = "Comedy"
                },
                    new Genre
                {
                    Name = "Drama"
                },
                    new Genre
                {
                    Name = "Science Fiction"
                });
                context.SaveChanges();
            }
        }
Example #4
0
 public void CreateMovie(Movie movie)
 {
     context.Add(movie);
     context.SaveChanges();
 }