void UpdateDatabase()
 {
     _websitesContext.Entry(_website).State = _website.Id == 0 ?
                                              EntityState.Added :
                                              EntityState.Modified;
     _websitesContext.WebPages.AddRange(_sitePages as IEnumerable <WebPage>);
     _websitesContext.SaveChanges();
 }
예제 #2
0
        public void Seed()
        {
            _context.Database.Migrate();

            string adminRoleName = "Admin";
            string userRoleName  = "User";

            if (!_context.Roles.Any())
            {
                var roleNames = new[]
                {
                    "Admin",
                    "User"
                };

                foreach (var roleName in roleNames)
                {
                    var role = new IdentityRole(roleName)
                    {
                        NormalizedName = roleName.ToUpper()
                    };
                    _context.Roles.Add(role);
                }
            }

            if (!_context.Users.Any())
            {
                //Add admin account
                var admin = new User {
                    UserName = "******", Email = "*****@*****.**"
                };
                _userManager.CreateAsync(admin, "Password1").Wait();
                _userManager.AddToRoleAsync(admin, adminRoleName).Wait();

                //Add user account
                var user = new User {
                    UserName = "******", Email = "*****@*****.**"
                };
                _userManager.CreateAsync(user, "Password1").Wait();
                _userManager.AddToRoleAsync(user, userRoleName).Wait();
            }

            _context.SaveChanges();
        }