Beispiel #1
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new RazorPageBlogContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <RazorPageBlogContext> >()))
            {
                if (context.Articles.Any())
                {
                    return;
                }
                var tmp  = new List <Articles>();
                var tags = new StringBuilder();
                for (int i = 1; i <= 20; i++)
                {
                    var tag = RandomTag();
                    tmp.Add(new Articles
                    {
                        Id         = Guid.NewGuid(),
                        Title      = $"第{i}筆部落格",
                        Body       = LoremIpsum(),
                        CoverPhoto = $"http://placehold.it/750x300?text=This is {i}",
                        CreateDate = DateTime.UtcNow.AddDays(i),
                        Tags       = tag,
                    });
                    tags.Append(tag + ",");
                }

                var tagCloud = tags.ToString()
                               .Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)
                               .GroupBy(d => d)
                               .Select(d => new { Key = d.Key, Amount = d.Count() })
                               .ToList();
                foreach (var item in tagCloud)
                {
                    context.TagCloud.Add(new TagCloud
                    {
                        Id     = Guid.NewGuid(),
                        Name   = item.Key,
                        Amount = item.Amount
                    });
                }
                context.Articles.AddRange(tmp);
                context.SaveChanges();
            }
        }
Beispiel #2
0
 public DeleteModel(BlogEX.Data.RazorPageBlogContext context)
 {
     _context = context;
 }
Beispiel #3
0
 public EditModel(BlogEX.Data.RazorPageBlogContext context)
 {
     _context = context;
 }
Beispiel #4
0
 public IndexModel(BlogEX.Data.RazorPageBlogContext context)
 {
     _context = context;
 }