ChooseNotary fixes
This commit is contained in:
		
							parent
							
								
									365a6da48f
								
							
						
					
					
						commit
						b426163ac4
					
				| @ -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; } | ||||
|     } | ||||
| } | ||||
| @ -14,69 +14,68 @@ | ||||
|             <div class="col"> | ||||
|                 <h1>Notaryo Steps</h1> | ||||
|                 <div class="mt-3"> | ||||
|                     @await Component.InvokeAsync("NotaryoSteps", new { | ||||
|                         NotaryoSteps = new List<NotaryoStep>() { | ||||
|                             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 }, | ||||
|                         } | ||||
|                     }) | ||||
| 
 | ||||
|                     <form class="mt-3"> | ||||
|                     @await Component.InvokeAsync("NotaryoSteps", new | ||||
|                         { | ||||
|                             NotaryoSteps = new List<NotaryoStep>() { | ||||
|                                 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 }, | ||||
|                             } | ||||
|                         }) | ||||
|                     <form id="ChooseNotaryForm" method="post"> | ||||
|                         <div class="row my-4"> | ||||
|                             <div class="col"> | ||||
|                                 <div class="d-flex"> | ||||
|                                     <div class="form-check me-3"><input id="formCheck-3" class="form-check-input" type="radio" name="NewOrOld" checked /><label class="form-check-label" for="formCheck-3">I will choose a Notary Public myself</label></div> | ||||
|                                     <div class="form-check"><input id="formCheck-4" class="form-check-input" type="radio" name="NewOrOld" /><label class="form-check-label" for="formCheck-4">Automatically choose an immediately available Notary Public</label></div> | ||||
|                                     <div class="form-check"><input id="cheAutomatic" class="form-check-input" type="radio" asp-for="IsManualSelection" value="false" checked="@(Model.IsManualSelection ? "" : "checked")" /><label class="form-check-label" for="cheAutomatic">Automatically choose an immediately available Notary Public</label></div> | ||||
|                                     <div class="form-check ms-3"><input id="chkManual" class="form-check-input" type="radio" asp-for="IsManualSelection" value="true" checked="@(Model.IsManualSelection ? "checked" : "")" /><label class="form-check-label" for="chkManual">I will choose a Notary Public myself</label></div> | ||||
|                                 </div> | ||||
|                             </div> | ||||
|                         </div> | ||||
|                         <div class="row mt-3"> | ||||
|                             <div class="col-12 col-lg-8"> | ||||
|                                 <div class="input-group"><input class="form-control" type="text" placeholder="Find an Attorney" /><button class="btn btn-outline-secondary" type="button"><i class="fas fa-search"></i></button></div> | ||||
|                         <div id="ManualSelectionDiv"> | ||||
|                             <div class="row mt-3"> | ||||
|                                 <div class="col-12 col-lg-5 col-xl-4"> | ||||
|                                     <div class="input-group"> | ||||
|                                         <input class="form-control" type="text" placeholder="Find an Attorney" asp-for="SearchString" /> | ||||
|                                         <button class="btn btn-outline-secondary" type="submit" asp-page-handler="Search"><i class="fas fa-search"></i></button></div> | ||||
|                                 </div> | ||||
|                             </div> | ||||
|                             <div class="row mt-3"> | ||||
|                                 <div class="col"> | ||||
|                                     <div class="table-responsive"> | ||||
|                                         <table class="table"> | ||||
|                                             <thead> | ||||
|                                                 <tr> | ||||
|                                                     <th>Name of Attorney</th> | ||||
|                                                     <th>Office Location</th> | ||||
|                                                     <th></th> | ||||
|                                                 </tr> | ||||
|                                             </thead> | ||||
|                                             <tbody> | ||||
|                                                 @foreach (var row in Model.AvailableLawyers) | ||||
|                                                 { | ||||
|                                                     <tr> | ||||
|                                                         <td>@row.Name</td> | ||||
|                                                         <td>@row.OfficeLocation</td> | ||||
|                                                         <td class="text-end"><button data-uid="@row.Lawyer_UID" class="btn btn-secondary btn-sm availablelawyer__select__button" type="button">Select</button></td> | ||||
|                                                     </tr> | ||||
|                                                 } | ||||
|                                             </tbody> | ||||
|                                         </table> | ||||
|                                     </div> | ||||
|                                 </div> | ||||
|                             </div> | ||||
|                         </div> | ||||
|                         <div class="row mt-3"> | ||||
|                         <div class="row mt-4" id="AutomaticSelectionDiv"> | ||||
|                             <div class="col"> | ||||
|                                 <div class="table-responsive"> | ||||
|                                     <table class="table"> | ||||
|                                         <thead> | ||||
|                                             <tr> | ||||
|                                                 <th>Name of Attorney</th> | ||||
|                                                 <th>Office Location</th> | ||||
|                                                 <th></th> | ||||
|                                             </tr> | ||||
|                                         </thead> | ||||
|                                         <tbody> | ||||
|                                             <tr> | ||||
|                                                 <td>Athony Co</td> | ||||
|                                                 <td>123 Fictional Road, Manila</td> | ||||
|                                                 <td class="text-end"><button class="btn btn-secondary btn-sm" type="button">Select</button></td> | ||||
|                                             </tr> | ||||
|                                             <tr> | ||||
|                                                 <td>Jude Romano</td> | ||||
|                                                 <td>342 Fake Road, Marikina</td> | ||||
|                                                 <td class="text-end"><button class="btn btn-secondary btn-sm" type="button">Select</button></td> | ||||
|                                             </tr> | ||||
|                                         </tbody> | ||||
|                                     </table> | ||||
|                                 </div> | ||||
|                                 <nav> | ||||
|                                     <ul class="pagination"> | ||||
|                                         <li class="page-item"><a class="page-link" aria-label="Previous" href="#"><span aria-hidden="true">«</span></a></li> | ||||
|                                         <li class="page-item"><a class="page-link" href="#">1</a></li> | ||||
|                                         <li class="page-item"><a class="page-link" href="#">2</a></li> | ||||
|                                         <li class="page-item"><a class="page-link" href="#">3</a></li> | ||||
|                                         <li class="page-item"><a class="page-link" aria-label="Next" href="#"><span aria-hidden="true">»</span></a></li> | ||||
|                                     </ul> | ||||
|                                 </nav> | ||||
|                                 <p>Please click the Finish button to complete the Notaryo Steps.</p> | ||||
|                             </div> | ||||
|                         </div> | ||||
|                         <input type="hidden" asp-for="SelectedLawyer_UID" /> | ||||
|                         <div class="d-flex"> | ||||
|                             <div class="flex-grow-1"></div> | ||||
|                             <button class="btn btn-primary btn-lg" type="submit"> | ||||
|                                 SUBMIT | ||||
|                             <button id="FinishButton" class="btn btn-primary btn-lg" type="submit"> | ||||
|                                 FINISH | ||||
|                                 <i class="fas fa-flag-checkered ms-2"></i> | ||||
|                             </button> | ||||
|                         </div> | ||||
| @ -91,4 +90,5 @@ | ||||
| 
 | ||||
| @section Scripts { | ||||
|     <script src="/dist/js/jfa.min.js"></script> | ||||
|     <script src="~/Pages/Principal/NotaryoSteps/ChooseNotary.cshtml.js" asp-append-version="true"></script> | ||||
| } | ||||
| @ -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<AvailableLawyerViewModel> 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; } | ||||
|     } | ||||
|  | ||||
| @ -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(); | ||||
| })(); | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user