diff --git a/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs b/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs index 9c1f399f..f700a22f 100644 --- a/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs +++ b/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs @@ -367,40 +367,39 @@ public class EnvelopeController : ViewControllerBase if (DateTime.Now > erro.DateValid) return View("EnvelopeExpired"); - return await _envRcvService.ReadByUuidSignatureAsync(uuid: erro.Envelope!.Uuid, erro.Receiver!.Signature).ThenAsync( - SuccessAsync: async er => + var erRes = await _envRcvService.ReadByUuidSignatureAsync(uuid: erro.Envelope!.Uuid, erro.Receiver!.Signature); + if (erRes.IsFailed) { - var envelopeKey = (er.Envelope!.Uuid, er.Receiver!.Signature).ToEnvelopeKey(); - - //TODO: implement multi-threading to history process (Task) - var hist_res = await _historyService.RecordAsync((int)erro.EnvelopeId, erro.AddedWho, EnvelopeStatus.EnvelopeViewed); - if (hist_res.IsFailed) - { - _logger.LogError( - "Although the envelope was sent as read-only, the EnvelopeShared hisotry could not be saved. ReadOnly-Id: {readOnlyKey}\nEnvelope Receiver:\n{envelopeReceiver}", - readOnlyId, JsonConvert.SerializeObject(er)); - _logger.LogNotice(hist_res.Notices); - } - - if (er.Envelope.Documents?.FirstOrDefault() is DocumentDto doc && doc.ByteData is not null) - { - ViewData["DocumentBytes"] = doc.ByteData; - ViewData["EnvelopeKey"] = envelopeKey; - ViewData["IsReadOnly"] = true; - ViewData["ReadOnly"] = erro; - ViewData["PSPDFKitLicenseKey"] = _configuration["PSPDFKitLicenseKey"]; - return View("ShowEnvelope", er); - } - else - { - _logger.LogEnvelopeError(envelopeReceiverId: envelopeKey, message: "No document byte-data was found in ENVELOPE_DOCUMENT table."); - return this.ViewDocumentNotFound(); - } - }, - Fail: (messages, notices) => - { - _logger.LogNotice(notices); + _logger.LogNotice(erRes.Notices); return this.ViewEnvelopeNotFound(); - }); + } + var er = erRes.Data; + + var envelopeKey = (er.Envelope!.Uuid, er.Receiver!.Signature).ToEnvelopeKey(); + + //TODO: implement multi-threading to history process (Task) + var hist_res = await _historyService.RecordAsync((int)erro.EnvelopeId, erro.AddedWho, EnvelopeStatus.EnvelopeViewed); + if (hist_res.IsFailed) + { + _logger.LogError( + "Although the envelope was sent as read-only, the EnvelopeShared hisotry could not be saved. ReadOnly-Id: {readOnlyKey}\nEnvelope Receiver:\n{envelopeReceiver}", + readOnlyId, JsonConvert.SerializeObject(er)); + _logger.LogNotice(hist_res.Notices); + } + + if (er.Envelope.Documents?.FirstOrDefault() is DocumentDto doc && doc.ByteData is not null) + { + ViewData["DocumentBytes"] = doc.ByteData; + ViewData["EnvelopeKey"] = envelopeKey; + ViewData["IsReadOnly"] = true; + ViewData["ReadOnly"] = erro; + ViewData["PSPDFKitLicenseKey"] = _configuration["PSPDFKitLicenseKey"]; + return View("ShowEnvelope", er); + } + else + { + _logger.LogEnvelopeError(envelopeReceiverId: envelopeKey, message: "No document byte-data was found in ENVELOPE_DOCUMENT table."); + return this.ViewDocumentNotFound(); + } } } \ No newline at end of file