Пример #1
0
        public static async Task SeedAsync(BudgetContext context, ILoggerFactory loggerFactory)
        {
            try
            {
                if (!context.Category.Any())
                {
                    var categoryData = System.IO.File.ReadAllText("../Infrastructure/Data/DataSeed/Categories.json");

                    var category = JsonSerializer.Deserialize <List <Category> >(categoryData);

                    foreach (var item in category)
                    {
                        context.Category.Add(item);
                    }
                    await context.SaveChangesAsync();
                }


                if (!context.Record.Any())
                {
                    var recordData = System.IO.File.ReadAllText("../Infrastructure/Data/DataSeed/Records.json");


                    var record = JsonSerializer.Deserialize <List <Record> >(recordData);

                    foreach (var item in record)
                    {
                        context.Record.Add(item);
                    }
                    await context.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                var logger = loggerFactory.CreateLogger <BudgetContextSeed>();
                logger.LogError(ex.Message);
            }
        }
Пример #2
0
        public static async Task SeedAsync(BudgetContext context, ILoggerFactory loggerFactory)
        {
            try
            {
                if (!context.Categories.Any())
                {
                    var categoriesData = File.ReadAllText("../Infrastructure/Data/SeedData/CategoriesList.json");
                    var categories     = JsonSerializer.Deserialize <List <Category> >(categoriesData);

                    foreach (var item in categories)
                    {
                        context.Categories.Add(item);
                    }

                    await context.SaveChangesAsync();
                }

                if (!context.Spends.Any())
                {
                    var spendData = File.ReadAllText("../Infrastructure/Data/SeedData/SpendList.json");
                    var spends    = JsonSerializer.Deserialize <List <Spend> >(spendData);

                    foreach (var item in spends)
                    {
                        context.Spends.Add(item);
                    }

                    await context.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                var logger = loggerFactory.CreateLogger <BudgetContextSeed>();
                logger.LogError(ex.Message);
            }
        }
Пример #3
0
 public RecordRepository(BudgetContext context)
 {
     _context = context;
 }
Пример #4
0
 public GenericRepository(BudgetContext context)
 {
     _context = context;
 }
Пример #5
0
 public BudgetRepository(BudgetContext context)
 {
     _context = context;
 }
Пример #6
0
 public CategoryRepository(BudgetContext context)
 {
     _context = context;
 }