public async Task <bool> Execute(DeleteConfirmationCodeParameter parameter) { if (parameter == null) { throw new ArgumentNullException(nameof(parameter)); } _deleteConfirmationCodeParameterValidator.Check(parameter); var confirmationCode = await _officeDocumentConfirmationLinkStore.Get(parameter.ConfirmationCode); if (confirmationCode == null) { throw new ConfirmationCodeNotFoundException(); } var officeDocument = await _officeDocumentRepository.Get(confirmationCode.DocumentId); if (officeDocument == null) { throw new DocumentNotFoundException(); } if (officeDocument.Subject != parameter.Subject) { throw new NotAuthorizedException(ErrorCodes.InternalError, ErrorDescriptions.NotAuthorized); } if (!await _officeDocumentConfirmationLinkStore.Remove(parameter.ConfirmationCode)) { throw new BaseDocumentManagementApiException(ErrorCodes.InternalError, ErrorDescriptions.CannotRemoveConfirmationCode); } return(true); }
/// <summary> /// Use the confirmation code. /// </summary> /// <param name="officeDocumentConfirmationLink"></param> /// <returns></returns> private async Task UseConfirmationLink(OfficeDocumentConfirmationLink officeDocumentConfirmationLink) { if (officeDocumentConfirmationLink.NumberOfConfirmations != null) { var nbConfirmations = officeDocumentConfirmationLink.NumberOfConfirmations.Value; nbConfirmations--; officeDocumentConfirmationLink.NumberOfConfirmations = nbConfirmations; if (nbConfirmations == 0) { await _officeDocumentConfirmationLinkStore.Remove(officeDocumentConfirmationLink.ConfirmationCode); return; } await _officeDocumentConfirmationLinkStore.Update(officeDocumentConfirmationLink); return; } await _officeDocumentConfirmationLinkStore.Remove(officeDocumentConfirmationLink.ConfirmationCode); }