예제 #1
0
        public static void Initialize(BlogDbContext context)
        {
            context.Database.EnsureCreated();

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

            var posts = new BlogPost[]
            {
                new BlogPost {
                    Title = "Getting Started with EC2", Category = new BlogCategory {
                        Name = "AWS"
                    }, Content = "<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p><p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>"
                },
                new BlogPost {
                    Title = "Deploy your first CI/CD pipeline", Category = new BlogCategory {
                        Name = "EC2"
                    }, Content = "<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p><p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>"
                }
            };

            foreach (BlogPost s in posts)
            {
                context.Posts.Add(s);
            }
            context.SaveChanges();

            var categories = new BlogCategory[]
            {
                new BlogCategory {
                    Name = "AWS"
                },
                new BlogCategory {
                    Name = "EC2"
                },
                new BlogCategory {
                    Name = "S3"
                },
                new BlogCategory {
                    Name = "SES"
                },
            };

            foreach (BlogCategory c in categories)
            {
                context.Categories.Add(c);
            }
            context.SaveChanges();
        }
예제 #2
0
        public List <BlogCategory> GetBlogCategories()
        {
            _sqlHelper = new SqlHelper(_connString);
            DataTable           dt         = _sqlHelper.GetDataTable("select * from BlogCategory");
            List <BlogCategory> categories = new List <BlogCategory>();

            foreach (DataRow row in dt.Rows)
            {
                var cat = new BlogCategory {
                    Id = (int)row.ItemArray[0], Name = row.ItemArray[1].ToString()
                };
                categories.Add(cat);
            }
            return(categories);
            //return _blogDbContext.Categories.ToList<BlogCategory>();
        }