Exemplo n.º 1
0
        private async Task AddUser(IaeContext _ctx)
        {
            _ctx.Database.Migrate();


            if (!_ctx.Users.Any(x => x.Email == "*****@*****.**"))
            {
                // Add 'administrator' role
                var adminRole = await _ctx.Roles.FirstOrDefaultAsync(r => r.RoleName == "Administrator");

                if (adminRole == null)
                {
                    adminRole = new Role
                    {
                        RoleName           = "Administrator",
                        NormalizedRoleName = "ADMINISTRATOR"
                    };
                    _ctx.Roles.Add(adminRole);
                    await _ctx.SaveChangesAsync();
                }

                // Create admin user
                var adminUser = _ctx.Users.FirstOrDefault(u => u.UserName == "*****@*****.**");
                if (adminUser == null)
                {
                    adminUser = new User
                    {
                        UserName           = "******",
                        NormalizedUserName = "******",
                        Name            = "Vu",
                        Surname         = "Tran Anh",
                        Email           = "*****@*****.**",
                        NormalizedEmail = "*****@*****.**".ToUpper(),
                        IsActive        = true,
                        EmailConfirmed  = true,
                        PasswordHash    = "AQAAAAEAACcQAAAAEJtgQFVsPu2OwWrq0EmFohzSY1uzvWD474ucMUmwLek5A8iXuWpjIl061y4C2z5Fow==" //vdsFuturisx@2018
                    };

                    _ctx.Users.Add(adminUser);

                    _ctx.SaveChanges();

                    _ctx.UserRoles.AddRange(
                        new UserRole(adminUser.Id, adminRole.Id));

                    _ctx.SaveChanges();
                }
            }
        }
Exemplo n.º 2
0
 public IaeContextSeed(ILogger <IaeContext> logger, IaeContext context)
 {
     _logger = logger;
     _ctx    = context;
 }