diff --git a/src/MicroserviceComponents/IdentityService/CleanMicroserviceSystem.Themis.WebAPI/Controllers/UserController.cs b/src/MicroserviceComponents/IdentityService/CleanMicroserviceSystem.Themis.WebAPI/Controllers/UserController.cs index 3b0bc1af..0bc30553 100644 --- a/src/MicroserviceComponents/IdentityService/CleanMicroserviceSystem.Themis.WebAPI/Controllers/UserController.cs +++ b/src/MicroserviceComponents/IdentityService/CleanMicroserviceSystem.Themis.WebAPI/Controllers/UserController.cs @@ -622,9 +622,22 @@ private async Task UpdateUserRoles(OceanusUser user, IEnumerable - this.roleManager.RoleExistsAsync(role).Result && !this.userManager.IsInRoleAsync(user, role).Result) .ToArray(); + foreach (var roleToAdd in rolesToAdd) + { + if (!(await this.roleManager.RoleExistsAsync(roleToAdd))) + { + var result = await this.roleManager.CreateAsync(new OceanusRole() { Name = roleToAdd }); + if (!result.Succeeded) + { + foreach (var error in result.Errors) + { + commonResult.Errors.Add(new CommonResultError(error.Code, error.Description)); + } + } + } + } if (rolesToAdd.Any()) { var result = await this.userManager.AddToRolesAsync(user, rolesToAdd);