public async Task DeleteRole(Role role) { if ((await _roleTable.SelectById(role.Id)).Any()) // Check that role exists { await _roleTable.Delete(role.Id); } else if (ValidateQuery(await _roleTable.SelectByName(role.Name), out role)) // Check that provided name exists { await _roleTable.Delete(role.Id); } else { throw new ArgumentException("No such role exists."); } }
public async Task <IdentityResult> DeleteAsync(TRole role, CancellationToken cancellationToken) { if (role == null) { throw new ArgumentNullException(nameof(role)); } try { var roleTableResult = await roleTable.Delete(role.Id, cancellationToken); if (roleTableResult > 0) { return(IdentityResult.Success); } else { return(IdentityResult.Failed(new IdentityError() { Code = roleTableResult.ToString(), Description = "Error during role deletion" })); } } catch (Exception ex) { return(IdentityResult.Failed(new IdentityError() { Code = ex.HResult.ToString(), Description = ex.Message })); } }