public UnitOfWork(PremiumCalculatorDbContext premiumCalculatorContext,
                   CustomerRepo.ICustomerRepository customerRepository,
                   OccupationRepo.IOccupationRepository occupationRepository,
                   OccupationRatingRepo.IOccupationRatingRepository occupationRatingRepository
                   )
 {
     this.premiumCalculatorContext   = premiumCalculatorContext;
     this.customerRepository         = customerRepository;
     this.occupationRepository       = occupationRepository;
     this.occupationRatingRepository = occupationRatingRepository;
 }
Example #2
0
 /// <summary>
 /// This method is used to generate deed data for Customer Entity
 /// </summary>
 /// <param name="context"></param>
 public static void SeedData(PremiumCalculatorDbContext context)
 {
     if (!context.OccupationRatings.Any())
     {
         var occupationRatings = GetOccupationRatingsSeedData();
         context.OccupationRatings.AddRange(occupationRatings);
         context.SaveChanges();
     }
     if (!context.Occupations.Any())
     {
         var occupations = GetOccupationsSeedData();
         context.Occupations.AddRange(occupations);
         context.SaveChanges();
     }
     if (!context.Customers.Any())
     {
         var customers = GetCustomersSeedData();
         context.Customers.AddRange(customers);
         context.SaveChanges();
     }
 }
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    PremiumCalculatorDbContext context = services.GetRequiredService <PremiumCalculatorDbContext>();
                    context.Database.Migrate();
                    Seed.SeedData(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured during migration");
                }
            }
            host.Run();
        }
Example #4
0
 public OccupationRatingRepository(PremiumCalculatorDbContext context)
     : base(context)
 {
 }
 public CustomerRepository(PremiumCalculatorDbContext context)
     : base(context)
 {
 }