diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadDocument.cshtml b/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadDocument.cshtml index 1009e29..ea54125 100644 --- a/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadDocument.cshtml +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadDocument.cshtml @@ -24,12 +24,83 @@ })
-
+ +
+
+
+ + + @Html.ValidationMessageFor(x => x.DocumentFile) +
- @await Component.InvokeAsync("UploadOrChooseIdentificationDocument", Model.Transaction_UID) -
+
+ +
+
+ + +
+ @Html.ValidationMessageFor(x => x.DocumentType) +
+
+
+
+ +
+ Email + + +
+
+ +
+
    +
+
+
+ +
+ Email + + +
+
+ +
+
    +
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+ + +
+ @Html.ValidationMessageFor(x => x.IsConfirmed) +
+
+ + +
- +
diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadDocument.cshtml.cs b/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadDocument.cshtml.cs index 39ec09c..d71a0d2 100644 --- a/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadDocument.cshtml.cs +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadDocument.cshtml.cs @@ -1,66 +1,123 @@ using System.ComponentModel.DataAnnotations; +using System.Text.Json; using Coravel.Queuing.Interfaces; using EnotaryoPH.Data; +using EnotaryoPH.Data.Entities; using EnotaryoPH.Web.Common.Jobs; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Rendering; namespace EnotaryoPH.Web.Pages.Principal.NotaryoSteps { - public class UploadDocumentModel : BaseIdentificationDocumentPageModel + public class UploadDocumentModel : PageModel { private readonly ICurrentUserService _currentUserService; + private readonly NotaryoDBContext _notaryoDBContext; private readonly IQueue _queue; public UploadDocumentModel(NotaryoDBContext notaryoDBContext, ICurrentUserService currentUserService, IQueue queue) - : base(notaryoDBContext) { + _notaryoDBContext = notaryoDBContext; _currentUserService = currentUserService; _queue = queue; } - public void OnGet() + public IActionResult OnGet(Guid transaction_UID) { + var _transaction = _notaryoDBContext.Transactions + .Include(t => t.TransactionDocument) + .Include(t => t.TransactionSignatories) + .AsNoTracking().FirstOrDefault(e => e.Transaction_UID == transaction_UID); + DocumentTypes = GetDocumentTypes(); + CurrentUserEmail = _currentUserService.GetEmail(); + var signatories = _transaction.TransactionSignatories.Select(ts => new SignatoryViewModel + { + Email = ts.Email, + Type = ts.Type, + UID = ts.TransactionSignatory_UID.GetValueOrDefault() + }).ToList(); + ParticipantsJson = JsonSerializer.Serialize(signatories); + + return Page(); } public async Task OnPostAsync() { - if (UploadNewIdentification) + if (!ModelState.IsValid) { - if (!ModelState.IsValid) - { - return Page(); - } - - CreateIdentificationDocument(_currentUserService.GetUser_UID()); + DocumentTypes = GetDocumentTypes(); + return Page(); } - SendSignatoryInvitations(); + if (!IsConfirmed) + { + ModelState.AddModelError(nameof(IsConfirmed), "You must tick this box to continue."); + DocumentTypes = GetDocumentTypes(); + return Page(); + } - return Redirect($"/Principal/NotaryoSteps/ChooseNotary/{Transaction_UID}"); - } - - private void SendSignatoryInvitations() - { var transaction = _notaryoDBContext.Transactions - .Include(e => e.TransactionSignatories) - .FirstOrDefault(e => e.Transaction_UID == Transaction_UID); + .Include(t => t.TransactionSignatories) + .Include(t => t.TransactionDocument) + .FirstOrDefault(t => t.Transaction_UID == Transaction_UID); + if (transaction == null) + { + return NotFound(); + } + + transaction.Status = nameof(TransactionState.DocumentUploaded); + transaction.IsRecorded = IsVideoConferenceRecorded; + + if (transaction.TransactionDocument == null) + { + transaction.TransactionDocument = new TransactionDocument + { + CreatedOn = DateTime.UtcNow, + Transaction = transaction, + TransactionDocument_UID = Guid.CreateVersion7(DateTime.UtcNow), + }; + } + + var stream = new MemoryStream((int)DocumentFile.Length); + DocumentFile.CopyTo(stream); + transaction.TransactionDocument.File = stream.ToArray(); + transaction.TransactionDocument.Filename = DocumentFile.FileName; + transaction.TransactionDocument.DocumentType = DocumentType; + transaction.TransactionDocument.UploadedOn = DateTime.UtcNow; + + var participants = JsonSerializer.Deserialize>(ParticipantsJson, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }) ?? []; + transaction.TransactionSignatories = participants.Select(p => new TransactionSignatory + { + CreatedOn = DateTime.UtcNow, + Email = p.Email, + Status = nameof(SignatoryStatus.New), + TransactionSignatory_UID = Guid.CreateVersion7(DateTime.UtcNow), + Type = p.Type, + InvitationCode = Guid.CreateVersion7(DateTime.UtcNow).ToString() + }).ToList(); + + _notaryoDBContext.Update(transaction); + _notaryoDBContext.SaveChanges(); + foreach (var signatory in transaction.TransactionSignatories) { _queue.QueueInvocableWithPayload(signatory.TransactionSignatory_UID.GetValueOrDefault()); } + + return Redirect($"/Principal/NotaryoSteps/ChooseNotary/{Transaction_UID}"); } - //private List GetDocumentTypes() - //{ - // var lookupIdentificationTypes = _notaryoDBContext.LookupData.AsNoTracking().Include(e => e.LookupDataValues).FirstOrDefault(e => e.Name == "Document Types"); - // return lookupIdentificationTypes.LookupDataValues - // .ConvertAll(m => new SelectListItem - // { - // Text = m.Title.DefaultIfEmpty(m.Value), - // Value = m.Value - // }); - //} + private List GetDocumentTypes() + { + var lookupIdentificationTypes = _notaryoDBContext.LookupData.AsNoTracking().Include(e => e.LookupDataValues).FirstOrDefault(e => e.Name == "Document Types"); + return lookupIdentificationTypes.LookupDataValues + .ConvertAll(m => new SelectListItem + { + Text = m.Title.DefaultIfEmpty(m.Value), + Value = m.Value + }); + } public string CurrentUserEmail { get; private set; }