Example #1
0
        public void CreateRoles(IServiceProvider serviceProvider)
        {
            var RoleList = ApplicationPermissions.GetAllRoles();

            try
            {
                using (var rolemand = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >())
                {
                    foreach (var role in RoleList)
                    {
                        var roleExist = rolemand.RoleExistsAsync(role.Name).Result;
                        if (!roleExist)
                        {
                            var result = rolemand.CreateAsync(new IdentityRole(role.Name)).Result;
                            if (!result.Succeeded)
                            {
                                //Do Something?
                                throw new NotImplementedException();
                            }
                        }
                    }
                }
            }
            catch (Exception Ex)
            {
                return;
            }
        }