upload identification step

This commit is contained in:
jojo aquino 2024-12-24 08:19:07 +00:00
parent 7d037d7308
commit 7aab4bce2d
8 changed files with 265 additions and 1 deletions

View File

@ -9,7 +9,9 @@ namespace EnotaryoPH.Web.Common.Models
var entity = new IdentificationDocument var entity = new IdentificationDocument
{ {
UploadedOn = DateTime.UtcNow, UploadedOn = DateTime.UtcNow,
UserID = userID UserID = userID,
IdentificationDocument_UID = Guid.NewGuid(),
CreatedOn = DateTime.UtcNow
}; };
return model.ToEntity(entity); return model.ToEntity(entity);

View File

@ -0,0 +1,100 @@
@page
@using EnotaryoPH.Web.Pages.Shared.Components.NotaryoSteps
@model UploadIdentificationModel
@{
}
@section Head {
<link href="\lib\fontawesome-free-6.7.1-web\css\all.min.css" rel="stylesheet" />
}
<section class="my-5">
<div class="container">
<div class="row">
<div class="col">
<h1>Notaryo Steps</h1>
<div class="mt-3">
@await Component.InvokeAsync("NotaryoSteps", new { NotaryoSteps = new List<NotaryoStep>() {
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 },
}})
<div class="tab-content mt-3"></div>
</div>
<form class="mt-4" id="UploadIdentificationForm" method="post" enctype="multipart/form-data">
@if (Model.ExistingIdentificationDocuments.Count > 0)
{
<div class="row mt-4 mb-3">
<div class="col">
<div class="d-flex">
<div class="form-check me-2"><input asp-for="UploadNewIdentification" id="UploadNewIdentificationYes" class="form-check-input" type="radio" value="true" /> <label class="form-check-label me-3" for="UploadNewIdentificationYes">Upload a new Identification Document</label></div>
<div class="form-check me-2"><input asp-for="UploadNewIdentification" id="UploadNewIdentificationNah" class="form-check-input" type="radio" value="false" /><label class="form-check-label me-3" for="UploadNewIdentificationNah">Use any of the existing Identification Documents</label></div>
</div>
</div>
</div>
}
else {
<input type="hidden" asp-for="UploadNewIdentification" />
}
<div id="NewIdentificationDocumentContainer">
@Html.EditorFor(m => m.NewIdentificationDocument)
</div>
@if (Model.ExistingIdentificationDocuments.Count > 0)
{
<div id="ExistingDocumentsContainer">
<div class="row mt-4">
<div class="col">
<h4>Existing Identification Documents</h4>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Identification Document Type</th>
<th>Expiration</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach(var id in Model.ExistingIdentificationDocuments)
{
<tr class="existingdocument__row">
<td>@id.IdentificationType</td>
<td>@id.ExpirationDate.Value.ToShortDateString()</td>
<td>
<button class="btn btn-danger btn-sm identificationdocument__delete__button" type="button" data-uid="@id.IdentificationDocument_UID">
<i class="fas fa-times me-1"></i>
<span class="d-none d-md-inline-block">Delete</span>
</button>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
</div>
</div>
}
<div class="d-flex mt-3">
<div class="flex-grow-1"></div>
<button class="btn btn-primary btn-lg wizard__nextbutton" type="submit">NEXT<i class="fas fa-chevron-right ms-2"></i></button>
</div>
</form>
</div>
</div>
</div>
</section>
<input type="hidden" asp-for="ExistingIdentificationDocumentCount" />
@section Scripts {
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<partial name="_ValidationScriptsPartial" />
<script src="\dist\js\jfa.min.js"></script>
<script src="\js\identification-document.js"></script>
<script src="~/Pages/Principal/NotaryoSteps/UploadIdentification.cshtml.js" asp-append-version="true"></script>
}

View File

@ -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<IActionResult> 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<IActionResult> 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<SelectListItem> 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<IdentificationDocumentModel> GetIdentityDocumentsByUserID(int userID) =>
_notaryoDBContext.IdentificationDocuments.AsNoTracking()
.Where(d => d.UserID == userID)
.Select(d => new IdentificationDocumentModel(d)).ToList();
public int ExistingIdentificationDocumentCount => ExistingIdentificationDocuments.Count;
public List<IdentificationDocumentModel> ExistingIdentificationDocuments { get; set; } = [];
[BindProperty(SupportsGet = true)]
public Guid IdentificationDocument_UID { get; set; }
[BindProperty]
public IdentificationDocumentModel NewIdentificationDocument { get; set; }
[BindProperty]
public bool UploadNewIdentification { get; set; }
}
}

View File

@ -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();
})();

View File

@ -0,0 +1,14 @@
@model List<NotaryoStep>
<div class="mt-3">
<ul id="transactionwizardnav" class="nav nav-pills nav-justified d-block d-sm-flex" role="tablist">
@foreach(var step in Model)
{
<li class="nav-item" role="presentation">
<a class="nav-link disabled @(step.IsActive ? "active" : "")" role="tab" data-bs-toggle="pill" href="#tab-1">
<div><span class="badge rounded-pill fs-6 me-1">STEP @step.Step</span></div><span class="text-dark step-text">@step.Name</span>
</a>
</li>
}
</ul>
<div class="tab-content mt-3"></div>
</div>

View File

@ -0,0 +1,9 @@
using Microsoft.AspNetCore.Mvc;
namespace EnotaryoPH.Web.Pages.Shared.Components.NotaryoSteps
{
public class NotaryoStepsViewComponent : ViewComponent
{
public async Task<IViewComponentResult> InvokeAsync(List<NotaryoStep> notaryoSteps) => View(notaryoSteps);
}
}

View File

@ -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; }
}
}

View File

@ -1,3 +1,4 @@
@using EnotaryoPH.Web @using EnotaryoPH.Web
@namespace EnotaryoPH.Web.Pages @namespace EnotaryoPH.Web.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, EnotaryoPH