Beispiel #1
0
        private static async Task SeedCurrencyAsync(BaseCleanArchitectureProjectDbContext dbContext, CancellationToken cancellationToken)
        {
            var real = new Currency()
            {
                Name    = "Real",
                Country = "Brazil",
                Symbol  = "R$",
                ISO     = "BRL"
            };
            var pound = new Currency()
            {
                Name    = "British Pound",
                Country = "UK",
                Symbol  = "£",
                ISO     = "GBP"
            };
            var euro = new Currency()
            {
                Name    = "Euro",
                Country = "EU",
                Symbol  = "€",
                ISO     = "EUR"
            };

            await CreateCurrencyIfNotExistAsync(dbContext, real, cancellationToken);
            await CreateCurrencyIfNotExistAsync(dbContext, pound, cancellationToken);
            await CreateCurrencyIfNotExistAsync(dbContext, euro, cancellationToken);
        }
        public static async Task SeedData(this BaseCleanArchitectureProjectDbContext dbContext, CancellationToken cancellationToken)
        {
            await SeedRolesAsync(dbContext, cancellationToken);
            await SeedAdministratorUser(dbContext, cancellationToken);

            await dbContext.SaveChangesAsync(cancellationToken);
        }
Beispiel #3
0
        private static async Task SeedAdministratorUserAsync(BaseCleanArchitectureProjectDbContext dbContext, CancellationToken cancellationToken)
        {
            var userStore = new UserStore <ApplicationUser, ApplicationRole, BaseCleanArchitectureProjectDbContext, Guid>(dbContext);

            using (var um = new UserManager <ApplicationUser>(userStore, null, new PasswordHasher <ApplicationUser>(), null, null, null, null, null, null)) {
                await CreateUserIfNotExistsAsync(um, "Admin", Role.ADMIN, cancellationToken).ConfigureAwait(false);
            }
        }
Beispiel #4
0
        private static async Task SeedRolesAsync(BaseCleanArchitectureProjectDbContext dbContext, CancellationToken cancellationToken)
        {
            var roleS = new RoleStore <ApplicationRole, BaseCleanArchitectureProjectDbContext, Guid>(dbContext);

            using (var rm = new RoleManager <ApplicationRole>(roleS, null, null, null, null)) {
                await AddRoleIfNotExist(Role.ADMIN, rm);
                await AddRoleIfNotExist(Role.User, rm);
            }
        }
Beispiel #5
0
        private static async Task CreateCurrencyIfNotExistAsync(BaseCleanArchitectureProjectDbContext dbContext, Currency currency, CancellationToken cancellationToken)
        {
            var exist = dbContext.Set <Currency>().FirstOrDefault(c => c.ISO == currency.ISO);

            if (exist == null)
            {
                await dbContext.Set <Currency>().AddAsync(currency, cancellationToken);
            }
        }
Beispiel #6
0
 public CustomerRepository(BaseCleanArchitectureProjectDbContext dbContext, IMapper autoMapper, IValidator <Customer> validator) : base(dbContext, autoMapper, validator)
 {
 }
 public Repository(BaseCleanArchitectureProjectDbContext dbContext, IMapper autoMapper, IValidator <T> validator)
 {
     _dbContext  = dbContext;
     _autoMapper = autoMapper;
     _validator  = validator;
 }