Example #1
0
        public static async Task SeedAsync(AssetContext context, ILoggerFactory loggerFactory)
        {
            try
            {
                var path = Path.GetDirectoryName(Environment.CurrentDirectory);

                // /Users/gbubemismith/Documents/coreApps/Hahn.ApplicationProcess.Application


                if (!context.Assets.Any())
                {
                    var assetsData = File.ReadAllText(path + @"/Hahn.ApplicationProcess.February2021.Data/Data/SeedData/assets.json");
                    var assets     = JsonSerializer.Deserialize <List <Asset> >(assetsData);

                    foreach (var item in assets)
                    {
                        context.Assets.Add(item);
                    }

                    await context.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                var logger = loggerFactory.CreateLogger <AssetContextSeed>();
                logger.LogError(ex.Message);
            }
        }
 public async Task <int> CompleteAsync()
 {
     return(await _context.SaveChangesAsync());
 }