protected override async Task ManageRepositoryAsync(ICreateContactCommand command, IRefreshableToken token) { NullGuard.NotNull(command, nameof(command)) .NotNull(token, nameof(token)); IContact contact = command.ToDomain(ContactRepository, AccountingRepository); IContact createdContact = await MicrosoftGraphRepository.CreateContactAsync(token, contact); if (createdContact == null) { return; } contact.ExternalIdentifier = createdContact.ExternalIdentifier; await ContactRepository.CreateOrUpdateContactSupplementAsync(contact); }
protected override async Task ManageRepositoryAsync(IUpdateContactCommand command, IRefreshableToken token) { NullGuard.NotNull(command, nameof(command)) .NotNull(token, nameof(token)); if (string.IsNullOrWhiteSpace(command.ExternalIdentifier)) { return; } IContact contact = command.ToDomain(ContactRepository, AccountingRepository); IContact existingContact = await command.GetExistingContactAsync(MicrosoftGraphRepository, ContactRepository); if (existingContact == null) { return; } string existingInternalIdentifier = existingContact.InternalIdentifier; if (string.IsNullOrWhiteSpace(existingInternalIdentifier) == false) { contact.InternalIdentifier = existingInternalIdentifier; } IContact updatedContact = await MicrosoftGraphRepository.UpdateContactAsync(token, contact); if (updatedContact == null) { return; } string updatedExternalIdentifier = updatedContact.ExternalIdentifier; if (string.IsNullOrWhiteSpace(updatedExternalIdentifier)) { return; } contact.ExternalIdentifier = updatedExternalIdentifier; await ContactRepository.CreateOrUpdateContactSupplementAsync(contact, existingContact.ExternalIdentifier); }