Ejemplo n.º 1
0
        public static async Task SeedArticles(CommandDbContext context)
        {
            if (await context.Articles.AnyAsync()) return;

            var articleData = await System.IO.File.ReadAllTextAsync(AppDomain.CurrentDomain.BaseDirectory + "/_SeedData/ArticleSeedData.json");
            var articlePhotoData = await System.IO.File.ReadAllTextAsync(AppDomain.CurrentDomain.BaseDirectory + "/_SeedData/ArticlePhotoSeedData.json");

            var articles = JsonSerializer.Deserialize<List<Article>>(articleData);
            var articlePhotos = JsonSerializer.Deserialize<List<ArticlePhoto>>(articlePhotoData);

            foreach (var article in articles)
            {
                context.Articles.Add(article);
            }

            await context.SaveChangesAsync();

            foreach (var articlePhoto in articlePhotos)
            {
                context.ArticlePhotos.Add(articlePhoto);
            }

            await context.SaveChangesAsync();
        }
Ejemplo n.º 2
0
 public async Task <bool> Commit()
 {
     return(await _context.SaveChangesAsync() > 0);
 }