152 lines
4.7 KiB
C#
152 lines
4.7 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using EnotaryoPH.Data;
|
|
using EnotaryoPH.Data.Entities;
|
|
using EnotaryoPH.Web.Common.Services;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace EnotaryoPH.Web.Pages
|
|
{
|
|
public class RegisterModel : PageModel
|
|
{
|
|
private readonly NotaryoDBContext _notaryoDBContext;
|
|
private readonly IPasswordService _passwordService;
|
|
|
|
public RegisterModel(NotaryoDBContext notaryoDBContext, IPasswordService passwordService)
|
|
{
|
|
_notaryoDBContext = notaryoDBContext;
|
|
_passwordService = passwordService;
|
|
}
|
|
|
|
public void OnGet()
|
|
{
|
|
RoleType = "Principal";
|
|
#if DEBUG
|
|
RollNumber = "ROLL1234";
|
|
IBPNumber = "IBP1234";
|
|
MCLEComplianceNumber = "MCLE1234";
|
|
MCLEDate = new DateTime(2023, 1, 15, 0, 0, 0, DateTimeKind.Utc);
|
|
PTRDate = new DateTime(2023, 1, 15, 0, 0, 0, DateTimeKind.Utc);
|
|
PTRLocation = "ptr location";
|
|
PTRNumber = "PTR98723";
|
|
CommissionExpiration = new DateTime(2023, 1, 15, 0, 0, 0, DateTimeKind.Utc);
|
|
CommissionLocation = "COMM LOC 8732";
|
|
CommissionNumber = "COMM NO 8392";
|
|
OfficeAddress = "123 Fictional Road, NY, Cubao";
|
|
|
|
PhoneNumber = "639151220001";
|
|
BirthDate = new DateTime(1979, 9, 10, 0, 0, 0, DateTimeKind.Utc);
|
|
Password = "arst1234";
|
|
ConfirmPassword = "arst1234";
|
|
|
|
|
|
#endif
|
|
}
|
|
|
|
public IActionResult OnPost()
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return Page();
|
|
}
|
|
|
|
var hasDuplicateEmail = _notaryoDBContext.Users.Any(u => EF.Functions.Like(u.Email, Email));
|
|
if (hasDuplicateEmail)
|
|
{
|
|
ModelState.AddModelError(nameof(Email), "That email already exists in the database.");
|
|
return Page();
|
|
}
|
|
|
|
var newUser = new User
|
|
{
|
|
BirthDate = new DateTime(BirthDate.Ticks, DateTimeKind.Utc),
|
|
Email = Email,
|
|
PasswordHash = _passwordService.HashPassword(Password),
|
|
PhoneNumber = PhoneNumber,
|
|
Role = RoleType
|
|
};
|
|
_notaryoDBContext.Users.Add(newUser);
|
|
|
|
if (RoleType == "Notary Public")
|
|
{
|
|
var newLawyer = new Lawyer
|
|
{
|
|
User = newUser,
|
|
CommissionExpiration = new DateTime(CommissionExpiration.Value.Ticks, DateTimeKind.Utc),
|
|
CommissionLocation = CommissionLocation,
|
|
CommissionNumber = CommissionNumber,
|
|
IBPNumber = IBPNumber,
|
|
MCLEComplianceNumber = MCLEComplianceNumber,
|
|
MCLEDate = new DateTime(MCLEDate.Value.Ticks, DateTimeKind.Utc),
|
|
OfficeAddress = OfficeAddress,
|
|
PTRDate = new DateTime(PTRDate.Value.Ticks, DateTimeKind.Utc),
|
|
PTRlocation = PTRLocation,
|
|
PTRNumber = PTRNumber,
|
|
Rollnumber = RollNumber,
|
|
Status = "New"
|
|
};
|
|
_notaryoDBContext.Lawyers.Add(newLawyer);
|
|
}
|
|
|
|
_notaryoDBContext.SaveChanges();
|
|
|
|
return RedirectToPage("/Principal/Dashboard");
|
|
}
|
|
|
|
[BindProperty]
|
|
public string Email { get; set; }
|
|
|
|
[BindProperty]
|
|
public string Password { get; set; }
|
|
|
|
[BindProperty]
|
|
[Compare(nameof(Password))]
|
|
public string ConfirmPassword { get; set; }
|
|
|
|
[BindProperty]
|
|
public string PhoneNumber { get; set; }
|
|
|
|
[BindProperty]
|
|
public DateTime BirthDate { get; set; }
|
|
|
|
[BindProperty]
|
|
public string RoleType { get; set; }
|
|
|
|
[BindProperty]
|
|
public string? RollNumber { get; set; }
|
|
|
|
[BindProperty]
|
|
public string? IBPNumber { get; set; }
|
|
|
|
[BindProperty]
|
|
public string? MCLEComplianceNumber { get; set; }
|
|
|
|
[BindProperty]
|
|
public DateTime? MCLEDate { get; set; }
|
|
|
|
[BindProperty]
|
|
public string? PTRNumber { get; set; }
|
|
|
|
[BindProperty]
|
|
public DateTime? PTRDate { get; set; }
|
|
|
|
[BindProperty]
|
|
public string? PTRLocation { get; set; }
|
|
|
|
[BindProperty]
|
|
public string? CommissionNumber { get; set; }
|
|
|
|
[BindProperty]
|
|
public DateTime? CommissionExpiration { get; set; }
|
|
|
|
[BindProperty]
|
|
public string? CommissionLocation { get; set; }
|
|
|
|
[BindProperty]
|
|
public string? OfficeAddress { get; set; }
|
|
|
|
[BindProperty]
|
|
public bool IsEighteenYearsOrOlder { get; set; }
|
|
}
|
|
} |