Exemplo n.º 1
0
        public async Task InsertCustomersSampleData(AngularNetCoreDbContext db)
        {
            var states = GetStates();

            db.States.AddRange(states);
            try
            {
                int numAffected = await db.SaveChangesAsync();

                _Logger.LogInformation(@"Saved {numAffected} states");
            }
            catch (Exception exp)
            {
                _Logger.LogError($"Error in {nameof(DbSeeder)}: " + exp.Message);
                throw;
            }

            var tasks = GetTasks();

            db.Tasks.AddRange(tasks);
            try
            {
                int numAffected = await db.SaveChangesAsync();

                _Logger.LogInformation(@"Saved {numAffected} tasks");
            }
            catch (Exception exp)
            {
                _Logger.LogError($"Error in {nameof(DbSeeder)}: " + exp.Message);
                throw;
            }

            var customers = GetCustomers(states);

            db.Customers.AddRange(customers);

            try
            {
                int numAffected = await db.SaveChangesAsync();

                _Logger.LogInformation($"Saved {numAffected} customers");
            }
            catch (Exception exp)
            {
                _Logger.LogError($"Error in {nameof(DbSeeder)}: " + exp.Message);
                throw;
            }
        }
Exemplo n.º 2
0
 public CustomersRepository(AngularNetCoreDbContext context, ILoggerFactory loggerFactory)
 {
     _Context = context;
     _Logger  = loggerFactory.CreateLogger("CustomersRepository");
 }