diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/AvailableLawyerViewModel.cs b/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/AvailableLawyerViewModel.cs new file mode 100644 index 0000000..ca03efc --- /dev/null +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/AvailableLawyerViewModel.cs @@ -0,0 +1,9 @@ +namespace EnotaryoPH.Web.Pages.Principal.NotaryoSteps +{ + public class AvailableLawyerViewModel + { + public Guid Lawyer_UID { get; set; } + public string Name { get; set; } + public string OfficeLocation { get; set; } + } +} \ No newline at end of file diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/ChooseNotary.cshtml b/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/ChooseNotary.cshtml index 4553aed..6bcaba5 100644 --- a/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/ChooseNotary.cshtml +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/ChooseNotary.cshtml @@ -14,69 +14,68 @@

Notaryo Steps

- @await Component.InvokeAsync("NotaryoSteps", new { - NotaryoSteps = new List() { - new NotaryoStep { Name = "Upload Identification", Step = 1 }, - new NotaryoStep { Name = "Take Selfie", Step = 2 }, - new NotaryoStep { Name = "Upload Document", Step = 3 }, - new NotaryoStep { Name = "Choose Notary", Step = 4, IsActive = true }, - } - }) - -
+ @await Component.InvokeAsync("NotaryoSteps", new + { + NotaryoSteps = new List() { + new NotaryoStep { Name = "Upload Identification", Step = 1 }, + new NotaryoStep { Name = "Take Selfie", Step = 2 }, + new NotaryoStep { Name = "Upload Document", Step = 3 }, + new NotaryoStep { Name = "Choose Notary", Step = 4, IsActive = true }, + } + }) +
-
-
+
+
-
-
-
+
+
+
+
+ +
+
+
+
+
+
+ + + + + + + + + + @foreach (var row in Model.AvailableLawyers) + { + + + + + + } + +
Name of AttorneyOffice Location
@row.Name@row.OfficeLocation
+
+
-
+
-
- - - - - - - - - - - - - - - - - - - - -
Name of AttorneyOffice Location
Athony Co123 Fictional Road, Manila
Jude Romano342 Fake Road, Marikina
-
- +

Please click the Finish button to complete the Notaryo Steps.

+
-
@@ -91,4 +90,5 @@ @section Scripts { + } \ No newline at end of file diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/ChooseNotary.cshtml.cs b/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/ChooseNotary.cshtml.cs index 4cb5f5f..27a1f5b 100644 --- a/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/ChooseNotary.cshtml.cs +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/ChooseNotary.cshtml.cs @@ -1,3 +1,4 @@ +using EnotaryoPH.Data; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; @@ -5,10 +6,80 @@ namespace EnotaryoPH.Web.Pages.Principal.NotaryoSteps { public class ChooseNotaryModel : PageModel { - public void OnGet() + private readonly ICurrentUserService _currentUserService; + private readonly NotaryoDBContext _notaryoDBContext; + + public ChooseNotaryModel(NotaryoDBContext notaryoDBContext, ICurrentUserService currentUserService) { + _notaryoDBContext = notaryoDBContext; + _currentUserService = currentUserService; } + public IActionResult OnGet() => OnPostSearch(); + + public IActionResult OnPost() + { + var transaction = _notaryoDBContext.Transactions.First(e => e.Transaction_UID == Transaction_UID); + if (IsManualSelection) + { + if (SelectedLawyer_UID == Guid.Empty) + { + ModelState.AddModelError(nameof(SelectedLawyer_UID), "Must select a notary public"); + return Page(); + } + + var lawyer = _notaryoDBContext.Lawyers.AsNoTracking().First(e => e.Lawyer_UID == SelectedLawyer_UID); + transaction.PreferredLawyerID = lawyer.LawyerID; + } + + transaction.Status = nameof(TransactionState.Submitted); + _notaryoDBContext.SaveChanges(); + + return Redirect($"/Principal/TransactionStatus/{transaction.Transaction_UID}"); + } + + public IActionResult OnPostSearch() + { + var user = _notaryoDBContext.Users.FirstOrDefault(e => e.User_UID == _currentUserService.GetUser_UID()); + + if (!_notaryoDBContext.Transactions.Any(e => e.Transaction_UID == Transaction_UID && e.PrincipalID == user.UserID)) + { + return NotFound(); + } + + AvailableLawyers = _notaryoDBContext.Lawyers + .Include(e => e.User) + .AsNoTracking() + .Where(e => e.Status == nameof(LawyerStatus.FingerprintScanned) && e.CommissionExpiration < DateTime.UtcNow) + .Select(e => new AvailableLawyerViewModel + { + Lawyer_UID = e.Lawyer_UID.GetValueOrDefault(), + Name = $"{e.User.Firstname} {e.User.Lastname}".NullIfWhiteSpace() ?? e.User.Email, + OfficeLocation = e.OfficeAddress + }) + .ToList(); + + if (!string.IsNullOrWhiteSpace(SearchString)) + { + AvailableLawyers = AvailableLawyers + .Where(m => m.Name.Contains(SearchString, StringComparison.OrdinalIgnoreCase)) + .ToList(); + } + + return Page(); + } + + public List AvailableLawyers { get; private set; } = []; + + [BindProperty] + public bool IsManualSelection { get; set; } + + [BindProperty(SupportsGet = true)] + public string SearchString { get; set; } + + [BindProperty] + public Guid SelectedLawyer_UID { get; set; } + [BindProperty(SupportsGet = true)] public Guid Transaction_UID { get; set; } } diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/ChooseNotary.cshtml.js b/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/ChooseNotary.cshtml.js new file mode 100644 index 0000000..a4abaa5 --- /dev/null +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/ChooseNotary.cshtml.js @@ -0,0 +1,66 @@ +"use strict"; +(function () { + const + control_automaticSelectionDiv = document.getElementById("AutomaticSelectionDiv"), + control_chooseNotaryForm = document.getElementById("ChooseNotaryForm"), + control_finishButton = document.getElementById("FinishButton"), + control_manualSelectionDiv = document.getElementById("ManualSelectionDiv"), + control_selectedIsManualSelection = document.querySelector("input[name='IsManualSelection']:checked"), + control_selectedLawyer_UID = document.getElementById("SelectedLawyer_UID"), + control_selectionRadioButtons = document.getElementsByName("IsManualSelection"), + control_selectLawyerButtons = document.querySelectorAll(".availablelawyer__select__button"); + + function _bindEvents() { + control_selectLawyerButtons?.forEach(btn => { + btn.addEventListener("click", _selectLawyer); + }); + + control_selectionRadioButtons.forEach(radio => { + radio.addEventListener("change", _radioOptionChanged) + }); + } + + function _init() { + _bindEvents(); + _showHideManualSelection(control_selectedIsManualSelection.value === "true"); + } + + function _radioOptionChanged(sender) { + let isManualSelection = sender?.target?.value ?? "true"; + _showHideManualSelection(isManualSelection === "true"); + } + + function _selectLawyer(e) { + let btn = e.target.closest("button"); + let tr = btn.closest("tr"); + tr.classList.add("table-primary"); + jfa.components.dialog.confirm({ + title: "Choose this notary public?", + message: "Are you sure you want to choose this notary public?", + callbackyes: function () { + control_selectedLawyer_UID.value = btn.dataset.uid; + + const urlObj = new URL(control_chooseNotaryForm.action); + urlObj.search = ''; + control_chooseNotaryForm.action = urlObj.toString(); + control_chooseNotaryForm.submit(); + }, + yesLabel: "Choose" + }); + } + + function _showHideManualSelection(isManualSelection) { + if (isManualSelection) { + jfa.utilities.element.show(control_manualSelectionDiv); + jfa.utilities.element.hide(control_automaticSelectionDiv); + jfa.utilities.element.disable(control_finishButton); + } + else { + jfa.utilities.element.hide(control_manualSelectionDiv); + jfa.utilities.element.show(control_automaticSelectionDiv); + jfa.utilities.element.enable(control_finishButton); + } + } + + _init(); +})(); \ No newline at end of file