public async Task SeedAsync(RecipeBookDbContext context, UserManager <ApplicationUser> userManager) { if (!context.Users.Any(x => x.NormalizedUserName == CreateTechAdminUserMigrationConstants.USERNAME.ToUpper())) { ApplicationUser adminUser = new ApplicationUser { FirstName = CreateTechAdminUserMigrationConstants.FIRST_NAME, LastName = CreateTechAdminUserMigrationConstants.LAST_NAME, Email = CreateTechAdminUserMigrationConstants.EMAIL, UserName = CreateTechAdminUserMigrationConstants.USERNAME, EmailConfirmed = true, LockoutEnabled = false, IsActive = true }; IdentityResult createdUserResult = await userManager.CreateAsync(adminUser, CreateTechAdminUserMigrationConstants.PASSWORD); if (createdUserResult.Succeeded) { foreach (RoleType roleType in CreateTechAdminUserMigrationConstants.ROLES) { await userManager.AddToRoleAsync(adminUser, roleType.ToDisplayName()); } } } }
public async Task <bool> DeleteAll(List <TEntity> entities) { await using RecipeBookDbContext context = this._factory.CreateDbContext(); context.Set <TEntity>().RemoveRange(entities); await context.SaveChangesAsync(); return(true); }
public async Task <TEntity> Update(TEntity entity) { await using RecipeBookDbContext context = this._factory.CreateDbContext(); context.Set <TEntity>().Update(entity); await context.SaveChangesAsync(); return(entity); }
public async Task <TEntity> Create(TEntity entity) { await using RecipeBookDbContext context = this._factory.CreateDbContext(); var newEntry = await context.Set <TEntity>().AddAsync(entity); await context.SaveChangesAsync(); return(newEntry.Entity); }
public async Task <List <TEntity> > FindBy(Func <TEntity, bool> predicate, Expression <Func <TEntity, object> >[] includes) { await using RecipeBookDbContext context = this._factory.CreateDbContext(); IQueryable <TEntity> query = context.Set <TEntity>(); query = includes.Aggregate(query, (current, expression) => current.Include(expression)); return(query.Where(predicate).ToList()); }
private static async Task Seed(RecipeBookDbContext context, UserManager <ApplicationUser> userManager, RoleManager <ApplicationRole> roleManager) { Type[] migrationTypes = MigrationHelper.GetMigrationTypes(); IRoleDataMigration addDefaultRolesMigration = MigrationHelper.GetMigration <AddDefaultRolesMigration>(migrationTypes); await addDefaultRolesMigration.SeedAsync(context, roleManager); IUserDataMigration createAdminUserDataMigration = MigrationHelper.GetMigration <CreateTechAdminUserMigration>(migrationTypes); await createAdminUserDataMigration.SeedAsync(context, userManager); }
public async Task SeedAsync(RecipeBookDbContext context, RoleManager <ApplicationRole> roleManager) { if (await context.Roles.AnyAsync()) { return; } foreach (RoleType roleType in AddDefaultRolesMigrationConstants.DEFAULT_ROLES) { await AddNewRole(roleManager, roleType); } }
public static IHost MigrateDatabase(this IHost host) { using (IServiceScope scope = host.Services.CreateScope()) { IServiceProvider serviceProvider = scope.ServiceProvider; RecipeBookDbContext context = serviceProvider.GetRequiredService <RecipeBookDbContext>(); UserManager <ApplicationUser> userManager = serviceProvider.GetRequiredService <UserManager <ApplicationUser> >(); RoleManager <ApplicationRole> roleManager = serviceProvider.GetRequiredService <RoleManager <ApplicationRole> >(); context.InitDatabase(userManager, roleManager).Wait(); } return(host); }
public DeleteRecipeCommandHandler(RecipeBookDbContext context) : base(context) { }
public async Task <List <TEntity> > FindBy(Func <TEntity, bool> predicate) { await using RecipeBookDbContext context = this._factory.CreateDbContext(); return(context.Set <TEntity>().Where(predicate).ToList()); }
public RecipeIngredientService(RecipeBookDbContext context) { _context = context; }
public RecipeRepository(RecipeBookDbContext dbContext) { _dbContext = dbContext; }
public async Task <TEntity> FindOneBy(Expression <Func <TEntity, bool> > predicate) { await using RecipeBookDbContext context = this._factory.CreateDbContext(); return(await context.Set <TEntity>().FirstOrDefaultAsync(predicate)); }
public CategoryRepository(RecipeBookDbContext dbContext) { _dbContext = dbContext; }
public DbMigrationFunction(RecipeBookDbContext context, AuthorizationManager authorizationManager) { _context = context; _authorizationManager = authorizationManager; }
public SaveShoppingListService(RecipeBookDbContext context) { _context = context; }
public CreateRecipeCommandHandler(RecipeBookDbContext context, IRecipeValidatorService recipeValidatorService, IRecipeIngredientService recipeIngredientService) : base(context) { _recipeValidatorService = recipeValidatorService; _recipeIngredientService = recipeIngredientService; }
public static async Task InitDatabase(this RecipeBookDbContext context, UserManager <ApplicationUser> userManager, RoleManager <ApplicationRole> roleManager) { await context.Database.MigrateAsync(); await Seed(context, userManager, roleManager); }
public SignInCommandHandler(RecipeBookDbContext context, SignInManager <ApplicationUser> signInManager) : base(context) { _signInManager = signInManager; }
public async Task <List <TEntity> > GetAll() { await using RecipeBookDbContext context = this._factory.CreateDbContext(); return(await context.Set <TEntity>().ToListAsync()); }
public HealthManager(RecipeBookDbContext dbContext, ILogger <HealthManager> log) { _dbContext = dbContext; _log = log; }
public async Task <TEntity> Find(TId id) { await using RecipeBookDbContext context = this._factory.CreateDbContext(); return(await context.Set <TEntity>().FindAsync(id)); }
public SaveShoppingListCommandHandler(RecipeBookDbContext context, ICurrentUserService currentUserService, ISaveShoppingListService saveShoppingListService) : base(context) { _saveShoppingListService = saveShoppingListService; _authorizedUserId = currentUserService.GetAuthorizedUserId(); }
protected CommandBase(RecipeBookDbContext context) { Context = context; }