예제 #1
0
 public void AddCategory(Category entity)
 {
     context.Categories.Add(entity);
     context.SaveChanges();
 }
예제 #2
0
        public void AddBlog(Blog entity)
        {
            context.Blogs.Add(entity);

            context.SaveChanges();
        }
예제 #3
0
 public void AddBlog(Blog blog)
 {
     _context.Blogs.Add(blog);
     _context.SaveChanges();
 }
 public void AddCategory(Category category)
 {
     context.Categories.Add(category);
     context.SaveChanges();
 }
예제 #5
0
        public static void Seed(IApplicationBuilder app)
        {
            BlogContext context = app.ApplicationServices.GetRequiredService <BlogContext>();

            context.Database.Migrate();

            if (!context.Categories.Any())
            {
                context.Categories.AddRange(
                    new Category {
                    Name = "Category 1"
                },
                    new Category {
                    Name = "Category 2"
                },
                    new Category {
                    Name = "Category 3"
                }
                    );


                context.SaveChanges();
            }

            if (!context.Blogs.Any())
            {
                context.Blogs.AddRange(
                    new Blog {
                    Title = "Blog title 1", Description = "Blog description", Body = "Blog 1 Body", Image = "1.jpg", Date = DateTime.Now.AddDays(-4), IsApproved = true, CategoryId = 1
                },
                    new Blog {
                    Title = "Blog title 2", Description = "Blog description", Body = "Blog 2 Body", Image = "2.jpg", Date = DateTime.Now.AddDays(-2), IsApproved = true, CategoryId = 1
                },
                    new Blog {
                    Title = "Blog title 3", Description = "Blog description", Body = "Blog 3 Body", Image = "3.jpg", Date = DateTime.Now.AddDays(-5), IsApproved = true, CategoryId = 2
                },
                    new Blog {
                    Title = "Blog title 4", Description = "Blog description", Body = "Blog 4 Body", Image = "4.jpg", Date = DateTime.Now.AddDays(-1), IsApproved = true, CategoryId = 1
                },
                    new Blog {
                    Title = "Blog title 5", Description = "Blog description", Body = "Blog 5 Body", Image = "5.jpg", Date = DateTime.Now.AddDays(-31), IsApproved = true, CategoryId = 2
                },
                    new Blog {
                    Title = "Blog title 6", Description = "Blog description", Body = "Blog 6 Body", Image = "6.jpg", Date = DateTime.Now.AddDays(-16), IsApproved = false, CategoryId = 2
                },
                    new Blog {
                    Title = "Blog title 7", Description = "Blog description", Body = "Blog 7 Body", Image = "7.jpg", Date = DateTime.Now.AddDays(-43), IsApproved = true, CategoryId = 2
                },
                    new Blog {
                    Title = "Blog title 8", Description = "Blog description", Body = "Blog 8 Body", Image = "8.jpg", Date = DateTime.Now.AddDays(-13), IsApproved = true, CategoryId = 3
                },
                    new Blog {
                    Title = "Blog title 9", Description = "Blog description", Body = "Blog 9 Body", Image = "9.jpg", Date = DateTime.Now.AddDays(-5), IsApproved = true, CategoryId = 3
                },
                    new Blog {
                    Title = "Blog title 10", Description = "Blog description", Body = "Blog 10 Body", Image = "10.jpg", Date = DateTime.Now.AddDays(-8), IsApproved = false, CategoryId = 3
                }
                    );

                context.SaveChanges();
            }
        }
예제 #6
0
        public static void Seed(IApplicationBuilder app)
        {
            BlogContext context = app.ApplicationServices.GetRequiredService <BlogContext>();

            context.Database.Migrate();

            if (!context.Categories.Any())
            {
                context.Categories.AddRange(
                    new Category()
                {
                    Name = "Category 1"
                },
                    new Category()
                {
                    Name = "Category 2"
                },
                    new Category()
                {
                    Name = "Category 3"
                }
                    );
                context.SaveChanges();
            }

            if (context.Blogs.Any())
            {
                return;
            }
            context.Blogs.AddRange(
                new Blog()
            {
                Name        = "blog Title 1",
                Description = "Blog Description 1",
                Body        = "Blog Body 1",
                Image       = "1.jpg",
                Date        = DateTime.Now.AddDays(-5),
                IsApproved  = true,
                CategoryId  = 1
            },
                new Blog()
            {
                Name        = "blog Title 2",
                Description = "Blog Description 2",
                Body        = "Blog Body 2",
                Image       = "2.jpg",
                Date        = DateTime.Now.AddDays(-5),
                IsApproved  = true,
                CategoryId  = 1
            },
                new Blog()
            {
                Name        = "blog Title 3",
                Description = "Blog Description 3",
                Body        = "Blog Body 3",
                Image       = "3.jpg",
                Date        = DateTime.Now.AddDays(-5),
                IsApproved  = false,
                CategoryId  = 2
            },
                new Blog()
            {
                Name        = "blog Title 4",
                Description = "Blog Description 4",
                Body        = "Blog Body 4",
                Image       = "4.jpg",
                Date        = DateTime.Now.AddDays(-5),
                IsApproved  = true,
                CategoryId  = 3
            }
                );
            context.SaveChanges();
        }