public Task Handle(ClaimAddedNotification notification, CancellationToken cancellationToken) { return(Task.Run(() => { var claim = notification.Claim; if (claim.Subject.Type != "thing") { return; } if (claim.Subject.Meta == null) { return; } claim.Subject.Meta.Id = claim.Subject.Id; // Ensure that the key has an ID value //var metaEntry = _trustDBContext.Entry(claim.Subject.Meta); var dbEntry = _trustDBContext.IdentityMetadata.Find(claim.Subject.Meta.Id); if (dbEntry == null) { _trustDBContext.Add(claim.Subject.Meta); } // The entry will be updated in database by a SaveChanges() some where else. })); }
public Task Handle(ClaimAddedNotification notification, CancellationToken cancellationToken) { return(Task.Run(() => { var claim = notification.Claim; if (claim.Issuer.Id != claim.Subject.Id) { return; // Not the same issuer and subject } if (!PackageBuilder.ALIAS_IDENTITY_DTP1.EqualsIgnoreCase(claim.Type)) { return; } var metadataId = claim.Issuer.Id; var entry = _trustDBContext.IdentityMetadata.Find(metadataId); if (entry == null) { entry = new IdentityMetadata { Id = metadataId, Title = claim.Value }; _trustDBContext.Add(entry); } else { entry.Title = claim.Value; } // The entry will be updated in database by a SaveChanges() some where else. })); }
private void UpdateEntry(Claim claim, Action <IdentityMetadata> callback) { var metadataId = claim.Issuer.Id; var entry = _trustDBContext.IdentityMetadata.Find(metadataId); if (entry == null) { entry = new IdentityMetadata { Id = metadataId, }; callback(entry); _trustDBContext.Add(entry); } else { callback(entry); } }