示例#1
0
        public static async Task SeedAsync(AspnetRunContext aspnetrunContext, ILoggerFactory loggerFactory, int?retry = 0)
        {
            int retryForAvailability = retry.Value;

            try
            {
                // TODO: Only run this if using a real database
                // aspnetrunContext.Database.Migrate();
                // aspnetrunContext.Database.EnsureCreated();

                if (!aspnetrunContext.Categories.Any())
                {
                    aspnetrunContext.Categories.AddRange(GetPreconfiguredCategories());
                    await aspnetrunContext.SaveChangesAsync();
                }

                if (!aspnetrunContext.Products.Any())
                {
                    aspnetrunContext.Products.AddRange(GetPreconfiguredProducts());
                    await aspnetrunContext.SaveChangesAsync();
                }
            }
            catch (Exception exception)
            {
                if (retryForAvailability < 10)
                {
                    retryForAvailability++;
                    var log = loggerFactory.CreateLogger <AspnetRunContextSeed>();
                    log.LogError(exception.Message);
                    await SeedAsync(aspnetrunContext, loggerFactory, retryForAvailability);
                }
                throw;
            }
        }
示例#2
0
 public AspnetRunContextSeed(
     AspnetRunContext aspnetRunContext,
     IProductRepository productRepository,
     IRepository <Category> categoryRepository)
 {
     _aspnetRunContext   = aspnetRunContext;
     _productRepository  = productRepository;
     _categoryRepository = categoryRepository;
 }
 public AspnetRunContextSeed(
     AspnetRunContext aspnetRunContext,
     UserManager <AspnetRunUser> userManager,
     IProductRepository productRepository,
     IRepository <Category> categoryRepository,
     IRepository <ProductSpecificationAssociation> prodSpecAssocRepository,
     IRepository <Specification> specificationRepository,
     IRepository <Customer> customerRepository,
     IRepository <Address> addressRepository,
     IRepository <Order> orderRepository)
 {
     _aspnetRunContext        = aspnetRunContext;
     _userManager             = userManager;
     _productRepository       = productRepository;
     _categoryRepository      = categoryRepository;
     _prodSpecAssocRepository = prodSpecAssocRepository;
     _specificationRepository = specificationRepository;
     _customerRepository      = customerRepository;
     _addressRepository       = addressRepository;
     _orderRepository         = orderRepository;
 }