コード例 #1
0
        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());
                    }
                }
            }
        }
コード例 #2
0
ファイル: DataService.cs プロジェクト: Cyecize/Recipe-Book
        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);
        }
コード例 #3
0
ファイル: DataService.cs プロジェクト: Cyecize/Recipe-Book
        public async Task <TEntity> Update(TEntity entity)
        {
            await using RecipeBookDbContext context = this._factory.CreateDbContext();
            context.Set <TEntity>().Update(entity);
            await context.SaveChangesAsync();

            return(entity);
        }
コード例 #4
0
ファイル: DataService.cs プロジェクト: Cyecize/Recipe-Book
        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);
        }
コード例 #5
0
ファイル: DataService.cs プロジェクト: Cyecize/Recipe-Book
        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());
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
        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);
        }
コード例 #9
0
 public DeleteRecipeCommandHandler(RecipeBookDbContext context) : base(context)
 {
 }
コード例 #10
0
ファイル: DataService.cs プロジェクト: Cyecize/Recipe-Book
 public async Task <List <TEntity> > FindBy(Func <TEntity, bool> predicate)
 {
     await using RecipeBookDbContext context = this._factory.CreateDbContext();
     return(context.Set <TEntity>().Where(predicate).ToList());
 }
コード例 #11
0
 public RecipeIngredientService(RecipeBookDbContext context)
 {
     _context = context;
 }
コード例 #12
0
 public RecipeRepository(RecipeBookDbContext dbContext)
 {
     _dbContext = dbContext;
 }
コード例 #13
0
ファイル: DataService.cs プロジェクト: Cyecize/Recipe-Book
 public async Task <TEntity> FindOneBy(Expression <Func <TEntity, bool> > predicate)
 {
     await using RecipeBookDbContext context = this._factory.CreateDbContext();
     return(await context.Set <TEntity>().FirstOrDefaultAsync(predicate));
 }
コード例 #14
0
 public CategoryRepository(RecipeBookDbContext dbContext)
 {
     _dbContext = dbContext;
 }
コード例 #15
0
 public DbMigrationFunction(RecipeBookDbContext context, AuthorizationManager authorizationManager)
 {
     _context = context;
     _authorizationManager = authorizationManager;
 }
コード例 #16
0
 public SaveShoppingListService(RecipeBookDbContext context)
 {
     _context = context;
 }
コード例 #17
0
 public CreateRecipeCommandHandler(RecipeBookDbContext context, IRecipeValidatorService recipeValidatorService, IRecipeIngredientService recipeIngredientService) : base(context)
 {
     _recipeValidatorService  = recipeValidatorService;
     _recipeIngredientService = recipeIngredientService;
 }
コード例 #18
0
        public static async Task InitDatabase(this RecipeBookDbContext context, UserManager <ApplicationUser> userManager, RoleManager <ApplicationRole> roleManager)
        {
            await context.Database.MigrateAsync();

            await Seed(context, userManager, roleManager);
        }
コード例 #19
0
 public SignInCommandHandler(RecipeBookDbContext context, SignInManager <ApplicationUser> signInManager) : base(context)
 {
     _signInManager = signInManager;
 }
コード例 #20
0
ファイル: DataService.cs プロジェクト: Cyecize/Recipe-Book
 public async Task <List <TEntity> > GetAll()
 {
     await using RecipeBookDbContext context = this._factory.CreateDbContext();
     return(await context.Set <TEntity>().ToListAsync());
 }
コード例 #21
0
 public HealthManager(RecipeBookDbContext dbContext, ILogger <HealthManager> log)
 {
     _dbContext = dbContext;
     _log       = log;
 }
コード例 #22
0
ファイル: DataService.cs プロジェクト: Cyecize/Recipe-Book
 public async Task <TEntity> Find(TId id)
 {
     await using RecipeBookDbContext context = this._factory.CreateDbContext();
     return(await context.Set <TEntity>().FindAsync(id));
 }
コード例 #23
0
 public SaveShoppingListCommandHandler(RecipeBookDbContext context, ICurrentUserService currentUserService, ISaveShoppingListService saveShoppingListService) : base(context)
 {
     _saveShoppingListService = saveShoppingListService;
     _authorizedUserId        = currentUserService.GetAuthorizedUserId();
 }
コード例 #24
0
 protected CommandBase(RecipeBookDbContext context)
 {
     Context = context;
 }