public async Task <IdentityResult> CreateAsync(TRole role, CancellationToken cancellationToken) { if (role == null) { throw new ArgumentNullException("role"); } try { var roleTableResult = await roleTable.Insert(role, cancellationToken); if (roleTableResult > 0) { return(IdentityResult.Success); } else { return(IdentityResult.Failed(new IdentityError() { Code = roleTableResult.ToString(), Description = "Error during role creation" })); } } catch (Exception ex) { return(IdentityResult.Failed(new IdentityError() { Code = ex.HResult.ToString(), Description = ex.Message })); } }
public async Task CreateRole(string name) { if (!(await _roleTable.SelectByName(name)).Any()) // Check if role name already exists { await _roleTable.Insert(name); } else { throw new ArgumentException("Provided role name already exists."); } }