From 45f6a7ee6c0e9d945ab9f2dbe957ed87598f3ceb Mon Sep 17 00:00:00 2001 From: jojo aquino Date: Mon, 24 Mar 2025 00:55:33 +0000 Subject: [PATCH] add Notary Transaction status button --- .../Notary/TransactionStatus/Index.cshtml | 60 ++++++++++ .../Notary/TransactionStatus/Index.cshtml.cs | 110 ++++++++++++++++++ .../TransactionStatus/SignatoryViewModel.cs | 9 ++ 3 files changed, 179 insertions(+) create mode 100644 EnotaryoPH/EnotaryoPH.Web/Pages/Notary/TransactionStatus/Index.cshtml create mode 100644 EnotaryoPH/EnotaryoPH.Web/Pages/Notary/TransactionStatus/Index.cshtml.cs create mode 100644 EnotaryoPH/EnotaryoPH.Web/Pages/Notary/TransactionStatus/SignatoryViewModel.cs diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Notary/TransactionStatus/Index.cshtml b/EnotaryoPH/EnotaryoPH.Web/Pages/Notary/TransactionStatus/Index.cshtml new file mode 100644 index 0000000..851e24e --- /dev/null +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Notary/TransactionStatus/Index.cshtml @@ -0,0 +1,60 @@ +@page "{Transaction_UID}" +@model EnotaryoPH.Web.Pages.Notary.TransactionStatus.IndexModel +@{ +} + +@section Head { + +} + +
+
+
+
+

@Model.Title

+ +
+
+

Started on @Model.StartedOn.ToShortDateString() @Model.StartedOn.ToShortTimeString().

+

@Model.StatusDescription

+ @if (Model.Signatories.Count > 0) { +
+ + + + + + + + + + @foreach(var row in Model.Signatories) + { + + + + + + } + +
EmailTypeStatus
@row.Email@row.Type@row.Status
+
+ } + +
+
+ +
+ @if(Model.IsTaken) { + BACK TO HOME  + } + else { +
+ +
+ } +
+
+
+
+
\ No newline at end of file diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Notary/TransactionStatus/Index.cshtml.cs b/EnotaryoPH/EnotaryoPH.Web/Pages/Notary/TransactionStatus/Index.cshtml.cs new file mode 100644 index 0000000..504dd8f --- /dev/null +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Notary/TransactionStatus/Index.cshtml.cs @@ -0,0 +1,110 @@ +using EnotaryoPH.Data; +using EnotaryoPH.Data.Entities; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace EnotaryoPH.Web.Pages.Notary.TransactionStatus +{ + public class IndexModel : PageModel + { + private const string STATUS_READY = "Ready"; + private readonly ICurrentUserService _currentUserService; + private readonly IConferenceSheduleService _conferenceSheduleService; + private readonly NotaryoDBContext _notaryoDBContext; + private Transaction? _transaction; + + public IndexModel(NotaryoDBContext notaryoDBContext, ICurrentUserService currentUserService, IConferenceSheduleService conferenceSheduleService) + { + _notaryoDBContext = notaryoDBContext; + _currentUserService = currentUserService; + _conferenceSheduleService = conferenceSheduleService; + } + + public IActionResult OnGet() + { + _transaction = _notaryoDBContext + .Transactions + .AsNoTracking() + .Include(t => t.TransactionSignatories) + .Include(t => t.TransactionDocument) + .Include(t => t.Principal) + .FirstOrDefault(e => e.Transaction_UID == Transaction_UID); + + if (_transaction == null) + { + return NotFound(); + } + + Title = _transaction.TransactionDocument.DocumentType; + StartedOn = _transaction.CreatedOn.GetValueOrDefault(); + StatusDescription = "Not all signatories have signed up to enotaryo and completed the onboarding process. This transaction cannot proceed until this has been resolved."; + + var signatories = _transaction.TransactionSignatories.ConvertAll(s => new SignatoryViewModel + { + Email = s.Email, + Type = s.Type, + Status = ChangeStatusLabel(s.Status) + }); + signatories.Add(new SignatoryViewModel + { + Email = _transaction.Principal.Email, + Status = STATUS_READY, + Type = nameof(UserType.Principal) + }); + + Signatories = signatories.OrderBy(sig => sig.Type).ThenBy(sig => sig.Email).ToList(); + + var isReady = Signatories.TrueForAll(sig => sig.Status == STATUS_READY); + if (isReady) + { + StatusDescription = _transaction.Status == nameof(TransactionState.Accepted) + ? "This transaction is already assigned to a lawyer and is being processed." + : "All signatories have signed up to enotaryo and completed the onboarding process. This transaction is ready to be processed."; + } + + return Page(); + } + + public async Task OnPostAsync() + { + _transaction = _notaryoDBContext + .Transactions + .Include(t => t.TransactionSignatories) + .FirstOrDefault(e => e.Transaction_UID == Transaction_UID); + if (_transaction == null) + { + return NotFound(); + } + + var user = _notaryoDBContext.Users.Single(u => u.User_UID == _currentUserService.GetUser_UID()); + var lawyer = _notaryoDBContext.Lawyers.Single(l => l.UserID == user.UserID); + _transaction.Status = nameof(TransactionState.Accepted); + _transaction.LawyerID = lawyer.LawyerID; + _notaryoDBContext.Update(_transaction); + + var schedule_UID = await _conferenceSheduleService.GetOrCreateScheduleIDAsync(Transaction_UID); + if (schedule_UID != Guid.Empty) + { + return _transaction.TransactionSignatories.TrueForAll(sig => sig.Status == nameof(SignatoryStatus.FaceMatch)) + ? Redirect($"/Participant/VideoCall/Room/{Transaction_UID}") + : Redirect($"/Participant/VideoCall/Waiting/{Transaction_UID}"); + } + + return Redirect("/Notary/Dashboard"); + } + + private string ChangeStatusLabel(string status) => status switch { nameof(SignatoryStatus.FaceMatch) => STATUS_READY, _ => status }; + + public bool IsTaken => string.Equals(_transaction?.Status, nameof(TransactionState.Accepted), StringComparison.OrdinalIgnoreCase); + public List Signatories { get; private set; } = []; + + public DateTime StartedOn { get; private set; } + + public string StatusDescription { get; private set; } + + public string Title { get; private set; } + + [BindProperty(SupportsGet = true)] + public Guid Transaction_UID { get; set; } + } +} \ No newline at end of file diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Notary/TransactionStatus/SignatoryViewModel.cs b/EnotaryoPH/EnotaryoPH.Web/Pages/Notary/TransactionStatus/SignatoryViewModel.cs new file mode 100644 index 0000000..ea30e06 --- /dev/null +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Notary/TransactionStatus/SignatoryViewModel.cs @@ -0,0 +1,9 @@ +namespace EnotaryoPH.Web.Pages.Notary.TransactionStatus +{ + public class SignatoryViewModel + { + public string Email { get; set; } + public string Status { get; set; } + public string Type { get; set; } + } +} \ No newline at end of file