diff --git a/EnotaryoPH/EnotaryoPH.Web/Common/Models/IdentificationDocumentModelMapper.cs b/EnotaryoPH/EnotaryoPH.Web/Common/Models/IdentificationDocumentModelMapper.cs index 5a68953..749fc5b 100644 --- a/EnotaryoPH/EnotaryoPH.Web/Common/Models/IdentificationDocumentModelMapper.cs +++ b/EnotaryoPH/EnotaryoPH.Web/Common/Models/IdentificationDocumentModelMapper.cs @@ -9,7 +9,9 @@ namespace EnotaryoPH.Web.Common.Models var entity = new IdentificationDocument { UploadedOn = DateTime.UtcNow, - UserID = userID + UserID = userID, + IdentificationDocument_UID = Guid.NewGuid(), + CreatedOn = DateTime.UtcNow }; return model.ToEntity(entity); diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadIdentification.cshtml b/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadIdentification.cshtml new file mode 100644 index 0000000..7ba10a5 --- /dev/null +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadIdentification.cshtml @@ -0,0 +1,100 @@ +@page +@using EnotaryoPH.Web.Pages.Shared.Components.NotaryoSteps + +@model UploadIdentificationModel +@{ +} + +@section Head { + +} + +
+
+
+
+

Notaryo Steps

+
+ @await Component.InvokeAsync("NotaryoSteps", new { NotaryoSteps = new List() { + new NotaryoStep { Name = "Choose Identification", Step = 1, IsActive = true }, + new NotaryoStep { Name = "Take Selfie", Step = 2 }, + new NotaryoStep { Name = "Upload Document", Step = 3 }, + new NotaryoStep { Name = "Choose Notary", Step = 4 }, + }}) +
+
+
+ + @if (Model.ExistingIdentificationDocuments.Count > 0) + { +
+
+
+
+
+
+
+
+ } + else { + + } + +
+ @Html.EditorFor(m => m.NewIdentificationDocument) +
+ @if (Model.ExistingIdentificationDocuments.Count > 0) + { +
+
+
+

Existing Identification Documents

+
+ + + + + + + + + + @foreach(var id in Model.ExistingIdentificationDocuments) + { + + + + + + } + +
Identification Document TypeExpiration
@id.IdentificationType@id.ExpirationDate.Value.ToShortDateString() + +
+
+
+
+
+ } +
+
+ +
+
+ +
+
+
+
+ + +@section Scripts { + + + + + +} diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadIdentification.cshtml.cs b/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadIdentification.cshtml.cs new file mode 100644 index 0000000..960461e --- /dev/null +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadIdentification.cshtml.cs @@ -0,0 +1,92 @@ +using EnotaryoPH.Data; +using EnotaryoPH.Web.Common.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.EntityFrameworkCore; + +namespace EnotaryoPH.Web.Pages.Principal.NotaryoSteps +{ + public class UploadIdentificationModel : PageModel + { + private readonly ICurrentUserService _currentUserService; + private readonly NotaryoDBContext _notaryoDBContext; + + public UploadIdentificationModel(NotaryoDBContext notaryoDBContext, ICurrentUserService currentUserService) + { + _notaryoDBContext = notaryoDBContext; + _currentUserService = currentUserService; + } + + public async Task OnGetAsync() + { + var user = _notaryoDBContext.Users.AsNoTracking().FirstOrDefault(u => u.User_UID == _currentUserService.GetUser_UID()); + if (user == null) + { + return BadRequest(); + } + ExistingIdentificationDocuments = GetIdentityDocumentsByUserID(user.UserID); + + NewIdentificationDocument = new IdentificationDocumentModel + { + IdentificationTypes = GetIdentificationDocumentTypes() + }; + + UploadNewIdentification = true; + + return Page(); + } + + [IgnoreAntiforgeryToken] + public async Task OnPostAsync() + { + if (UploadNewIdentification) + { + if (!ModelState.IsValid) + { + NewIdentificationDocument = new IdentificationDocumentModel + { + IdentificationTypes = GetIdentificationDocumentTypes() + }; + return Page(); + } + + var user = _notaryoDBContext.Users.AsNoTracking().FirstOrDefault(u => u.User_UID == _currentUserService.GetUser_UID()); + var entity = NewIdentificationDocument.ToEntity(user.UserID); + _notaryoDBContext.Add(entity); + _notaryoDBContext.SaveChanges(); + } + + return RedirectToPage("/Principal/NotaryoSteps/TakeSelfie"); + } + + private List GetIdentificationDocumentTypes() + { + var lookupIdentificationTypes = _notaryoDBContext.LookupData.AsNoTracking().Include(e => e.LookupDataValues).FirstOrDefault(e => e.Name == "Identification Types"); + return lookupIdentificationTypes.LookupDataValues + .ConvertAll(m => new SelectListItem + { + Text = m.Title.DefaultIfEmpty(m.Value), + Value = m.Value + }); + } + + private List GetIdentityDocumentsByUserID(int userID) => + _notaryoDBContext.IdentificationDocuments.AsNoTracking() + .Where(d => d.UserID == userID) + .Select(d => new IdentificationDocumentModel(d)).ToList(); + + public int ExistingIdentificationDocumentCount => ExistingIdentificationDocuments.Count; + + public List ExistingIdentificationDocuments { get; set; } = []; + + [BindProperty(SupportsGet = true)] + public Guid IdentificationDocument_UID { get; set; } + + [BindProperty] + public IdentificationDocumentModel NewIdentificationDocument { get; set; } + + [BindProperty] + public bool UploadNewIdentification { get; set; } + } +} \ No newline at end of file diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadIdentification.cshtml.js b/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadIdentification.cshtml.js new file mode 100644 index 0000000..17a77a0 --- /dev/null +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadIdentification.cshtml.js @@ -0,0 +1,37 @@ +"use strict"; +(function () { + const + control_existingDocumentsContainer = document.getElementById("ExistingDocumentsContainer"), + control_existingIdentificationDocumentCount = document.getElementById("ExistingIdentificationDocumentCount"), + control_newIdentificationDocumentContainer = document.getElementById("NewIdentificationDocumentContainer"), + control_nextButton = document.querySelector(".wizard__nextbutton"), + control_uploadIdentificationForm = document.getElementById("UploadIdentificationForm"), + control_uploadNewIdentificationRadios = document.getElementsByName("UploadNewIdentification"); + + function _bindEvents() { + + control_uploadNewIdentificationRadios.forEach(radio => { + radio.addEventListener("change", _radioOptionChanged) + }); + } + + function _init() { + _bindEvents(); + + _radioOptionChanged(null); + } + + function _radioOptionChanged(sender) { + let uploadNewIdentificationDocument = sender?.target?.value ?? "true"; + if (uploadNewIdentificationDocument === "true") { + jfa.utilities.element.hide(control_existingDocumentsContainer); + jfa.utilities.element.show(control_newIdentificationDocumentContainer) + } + else { + jfa.utilities.element.show(control_existingDocumentsContainer); + jfa.utilities.element.hide(control_newIdentificationDocumentContainer) + } + } + + _init(); +})(); \ No newline at end of file diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Shared/Components/NotaryoSteps/Default.cshtml b/EnotaryoPH/EnotaryoPH.Web/Pages/Shared/Components/NotaryoSteps/Default.cshtml new file mode 100644 index 0000000..4f34af1 --- /dev/null +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Shared/Components/NotaryoSteps/Default.cshtml @@ -0,0 +1,14 @@ +@model List +
+ +
+
\ No newline at end of file diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Shared/Components/NotaryoSteps/Default.cshtml.cs b/EnotaryoPH/EnotaryoPH.Web/Pages/Shared/Components/NotaryoSteps/Default.cshtml.cs new file mode 100644 index 0000000..3026770 --- /dev/null +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Shared/Components/NotaryoSteps/Default.cshtml.cs @@ -0,0 +1,9 @@ +using Microsoft.AspNetCore.Mvc; + +namespace EnotaryoPH.Web.Pages.Shared.Components.NotaryoSteps +{ + public class NotaryoStepsViewComponent : ViewComponent + { + public async Task InvokeAsync(List notaryoSteps) => View(notaryoSteps); + } +} \ No newline at end of file diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Shared/Components/NotaryoSteps/NotaryoStep.cs b/EnotaryoPH/EnotaryoPH.Web/Pages/Shared/Components/NotaryoSteps/NotaryoStep.cs new file mode 100644 index 0000000..8ade829 --- /dev/null +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Shared/Components/NotaryoSteps/NotaryoStep.cs @@ -0,0 +1,9 @@ +namespace EnotaryoPH.Web.Pages.Shared.Components.NotaryoSteps +{ + public class NotaryoStep + { + public bool IsActive { get; set; } + public string Name { get; set; } + public int Step { get; set; } + } +} \ No newline at end of file diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/_ViewImports.cshtml b/EnotaryoPH/EnotaryoPH.Web/Pages/_ViewImports.cshtml index 2b3e758..fd1bac9 100644 --- a/EnotaryoPH/EnotaryoPH.Web/Pages/_ViewImports.cshtml +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/_ViewImports.cshtml @@ -1,3 +1,4 @@ @using EnotaryoPH.Web @namespace EnotaryoPH.Web.Pages @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@addTagHelper *, EnotaryoPH \ No newline at end of file