Example #1
0
        public async void CreateRolesAsync(IContainer container)
        {
            IdentityRoleManager roleManager = container.Resolve <IdentityRoleManager>();

            IdentityUserManager userManager = container.Resolve <IdentityUserManager>();

            if (userManager.FindById(6) != null)
            {
                await userManager.AddToRoleAsync(6, Role.Admin.ToString());
            }

            if (userManager.FindById(7) != null)
            {
                await userManager.AddToRoleAsync(7, Role.Seller.ToString());
            }

            if (roleManager.FindByNameAsync(Role.Admin.ToString()).Result == null)
            {
                await roleManager.CreateAsync(new CustomRole(Role.Admin.ToString()));

                await userManager.AddToRoleAsync(1, Role.Admin.ToString());
            }
            if (roleManager.FindByNameAsync(Role.Seller.ToString()).Result == null)
            {
                await roleManager.CreateAsync(new CustomRole(Role.Seller.ToString()));
            }
            if (roleManager.FindByNameAsync(Role.Customer.ToString()).Result == null)
            {
                await roleManager.CreateAsync(new CustomRole(Role.Customer.ToString()));
            }
        }
Example #2
0
        private async Task ValidateRoleName(IdentityRoleManager manager, Role role,
                                            ICollection <IdentityError> errors)
        {
            var roleName = await manager.GetRoleNameAsync(role);

            if (string.IsNullOrWhiteSpace(roleName))
            {
                errors.Add(Describer.InvalidRoleName(roleName));
            }
            else
            {
                var owner = await manager.FindByNameAsync(roleName, role.CompanyId, role.TenantId);

                if (owner != null &&
                    !string.Equals(await manager.GetRoleIdAsync(owner), await manager.GetRoleIdAsync(role)))
                {
                    errors.Add(Describer.DuplicateRoleName(roleName));
                }
            }
        }
 private async Task <IdentityRole> GetRoleAsync(WorkflowExecutionContext executionContext, string name)
 => await _identityRoleManager.FindByNameAsync(name);
Example #4
0
 /// <summary>
 /// Finds role by name
 /// </summary>
 /// <param name="roleName">Gets role name</param>
 /// <returns>IdentityRole</returns>
 public Task <IdentityRole> FindByNameAsync(string roleName)
 {
     return(_roleManager.FindByNameAsync(roleName));
 }