public async Task SeedAsync(SpravkiDbContext dbContext, IServiceProvider serviceProvider) { if (dbContext.Users.Any()) { return; } var userManager = serviceProvider.GetRequiredService <UserManager <ApplicationUser> >(); string email = "*****@*****.**"; string roleName = "Administrator"; string password = "******"; var user = new ApplicationUser { UserName = email, Email = email, }; await userManager.CreateAsync(user, password); await userManager.AddToRoleAsync(user, roleName); await dbContext.SaveChangesAsync(); }
public async Task SeedAsync(SpravkiDbContext dbContext, IServiceProvider serviceProvider) { if (dbContext == null) { throw new ArgumentNullException(nameof(dbContext)); } if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)); } var logger = serviceProvider.GetService <ILoggerFactory>().CreateLogger(typeof(ApplicationDbContextSeeder)); var seeders = new List <ISeeder> { new RolesSeeder(), new AdministratorSeeder(), }; foreach (var seeder in seeders) { await seeder.SeedAsync(dbContext, serviceProvider); await dbContext.SaveChangesAsync(); logger.LogInformation($"Seeder {seeder.GetType().Name} done."); } }
public ProductsService(SpravkiDbContext db) { this.db = db; }
public async Task SeedAsync(SpravkiDbContext dbContext, IServiceProvider serviceProvider) { var roleManager = serviceProvider.GetRequiredService <RoleManager <ApplicationRole> >(); await SeedRoleAsync(roleManager, AdministratorRoleName); }
public SalesService(SpravkiDbContext db) { this.db = db; }
public PharmaciesService(SpravkiDbContext db) { this.db = db; }
public DistributorService(SpravkiDbContext db) { this.db = db; }
public CompaniesService(SpravkiDbContext db) { this.db = db; }
public RegionsService(SpravkiDbContext db) { this.db = db; }
public DistributorsController(SpravkiDbContext context) { this.context = context; }