Esempio n. 1
0
        public async Task InsertCustomersSampleData(CustomersDbContext 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(CustomersDbSeeder)}: " + 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(CustomersDbSeeder)}: " + exp.Message);
                throw;
            }
        }
Esempio n. 2
0
 public LookupRepository(CustomersDbContext context, ILoggerFactory loggerFactory)
 {
     _Context = context;
     _Logger  = loggerFactory.CreateLogger("LookupRepository");
 }