feat: implement AuthorizedPerson management with repository and application services
This commit is contained in:
@@ -21,4 +21,19 @@
|
|||||||
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Remove="Application\UID\UidService.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Remove="Application\AuthorizedPerson\AuthorizedPersonApplication.cs" />
|
||||||
|
<Compile Remove="Application\AuthorizedPerson\IAuthorizedPersonApplication.cs" />
|
||||||
|
<Compile Remove="Domain\AuthorizedPersonAgg\IAuthorizedPersonRepository.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Domain\AuthorizedPersonAgg\" />
|
||||||
|
<Folder Include="InfraStructure\AuthorizedPerson\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,79 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Net.Http.Json;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.Json;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace _0_Framework.Application.UID;
|
|
||||||
|
|
||||||
public class UidService : IUidService
|
|
||||||
{
|
|
||||||
private readonly HttpClient _httpClient;
|
|
||||||
private const string BaseUrl = "https://json-api.uid.ir/api/inquiry/";
|
|
||||||
|
|
||||||
public UidService()
|
|
||||||
{
|
|
||||||
_httpClient = new HttpClient()
|
|
||||||
{
|
|
||||||
BaseAddress = new Uri(BaseUrl)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<PersonalInfoResponse> GetPersonalInfo(string nationalCode, string birthDate)
|
|
||||||
{
|
|
||||||
var request = new PersonalInfoRequest
|
|
||||||
{
|
|
||||||
BirthDate = birthDate,
|
|
||||||
NationalId = nationalCode,
|
|
||||||
RequestContext = new UidRequestContext()
|
|
||||||
};
|
|
||||||
var json = JsonConvert.SerializeObject(request);
|
|
||||||
var contentType = new StringContent(json, Encoding.UTF8, "application/json");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var requestResult = await _httpClient.PostAsync("person/v2", contentType);
|
|
||||||
if (!requestResult.IsSuccessStatusCode)
|
|
||||||
return null;
|
|
||||||
var responseResult = await requestResult.Content.ReadFromJsonAsync<PersonalInfoResponse>();
|
|
||||||
if (responseResult.BasicInformation != null)
|
|
||||||
{
|
|
||||||
responseResult.BasicInformation.FirstName = responseResult.BasicInformation.FirstName?.ToPersian();
|
|
||||||
responseResult.BasicInformation.LastName = responseResult.BasicInformation.LastName?.ToPersian();
|
|
||||||
responseResult.BasicInformation.FatherName = responseResult.BasicInformation.FatherName?.ToPersian();
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseResult;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
|
|
||||||
return new PersonalInfoResponse(new UidBasicInformation(),
|
|
||||||
new IdentificationInformation(default, default, default, default, default), new RegistrationStatus(),
|
|
||||||
new ResponseContext(new UidStatus(14, "")));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<MatchMobileWithNationalCodeResponse> IsMachPhoneWithNationalCode(string nationalCode, string phoneNumber)
|
|
||||||
{
|
|
||||||
var request = new PersonalInfoRequest
|
|
||||||
{
|
|
||||||
MobileNumber = phoneNumber,
|
|
||||||
NationalId = nationalCode,
|
|
||||||
RequestContext = new UidRequestContext()
|
|
||||||
};
|
|
||||||
var json = JsonConvert.SerializeObject(request);
|
|
||||||
var contentType = new StringContent(json, Encoding.UTF8, "application/json");
|
|
||||||
|
|
||||||
var requestResult = await _httpClient.PostAsync("mobile/owner/v2", contentType);
|
|
||||||
if (!requestResult.IsSuccessStatusCode)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
var responseResult = await requestResult.Content.ReadFromJsonAsync<MatchMobileWithNationalCodeResponse>();
|
|
||||||
return responseResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
51
Company.Domain/AuthorizedPersonAgg/AuthorizedPerson.cs
Normal file
51
Company.Domain/AuthorizedPersonAgg/AuthorizedPerson.cs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using _0_Framework.Domain;
|
||||||
|
|
||||||
|
namespace Company.Domain.AuthorizedPersonAgg;
|
||||||
|
|
||||||
|
public class AuthorizedPerson : EntityBase
|
||||||
|
{
|
||||||
|
public string NationalCode { get; private set; }
|
||||||
|
public string FirstName { get; private set; }
|
||||||
|
public string LastName { get; private set; }
|
||||||
|
public string FatherName { get; private set; }
|
||||||
|
public string BirthDate { get; private set; }
|
||||||
|
public string Gender { get; private set; }
|
||||||
|
public string DeathStatus { get; private set; }
|
||||||
|
public string ShenasnameSeri { get; private set; }
|
||||||
|
public string ShenasnameSerial { get; private set; }
|
||||||
|
public string ShenasnamehNumber { get; private set; }
|
||||||
|
public bool IsVerified { get; private set; }
|
||||||
|
public DateTime? VerificationDate { get; private set; }
|
||||||
|
|
||||||
|
public AuthorizedPerson(string nationalCode, string firstName, string lastName, string fatherName,
|
||||||
|
string birthDate, string gender, string deathStatus, string shenasnameSeri,
|
||||||
|
string shenasnameSerial, string shenasnamehNumber)
|
||||||
|
{
|
||||||
|
NationalCode = nationalCode;
|
||||||
|
FirstName = firstName;
|
||||||
|
LastName = lastName;
|
||||||
|
FatherName = fatherName;
|
||||||
|
BirthDate = birthDate;
|
||||||
|
Gender = gender;
|
||||||
|
DeathStatus = deathStatus;
|
||||||
|
ShenasnameSeri = shenasnameSeri;
|
||||||
|
ShenasnameSerial = shenasnameSerial;
|
||||||
|
ShenasnamehNumber = shenasnamehNumber;
|
||||||
|
IsVerified = true;
|
||||||
|
VerificationDate = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdatePersonalInfo(string firstName, string lastName, string fatherName,
|
||||||
|
string gender, string deathStatus)
|
||||||
|
{
|
||||||
|
FirstName = firstName;
|
||||||
|
LastName = lastName;
|
||||||
|
FatherName = fatherName;
|
||||||
|
Gender = gender;
|
||||||
|
DeathStatus = deathStatus;
|
||||||
|
VerificationDate = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected AuthorizedPerson() { }
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using _0_Framework.Domain;
|
||||||
|
|
||||||
|
namespace Company.Domain.AuthorizedPersonAgg;
|
||||||
|
|
||||||
|
public interface IAuthorizedPersonRepository : IRepository<long, AuthorizedPerson>
|
||||||
|
{
|
||||||
|
AuthorizedPerson GetByNationalCode(string nationalCode);
|
||||||
|
bool ExistsByNationalCode(string nationalCode);
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
namespace CompanyManagment.App.Contracts.AuthorizedPerson;
|
||||||
|
|
||||||
|
public class AuthorizedPersonViewModel
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public string NationalCode { get; set; }
|
||||||
|
public string FirstName { get; set; }
|
||||||
|
public string LastName { get; set; }
|
||||||
|
public string FatherName { get; set; }
|
||||||
|
public string BirthDate { get; set; }
|
||||||
|
public string Gender { get; set; }
|
||||||
|
public string DeathStatus { get; set; }
|
||||||
|
public string ShenasnameSeri { get; set; }
|
||||||
|
public string ShenasnameSerial { get; set; }
|
||||||
|
public string ShenasnamehNumber { get; set; }
|
||||||
|
public bool IsVerified { get; set; }
|
||||||
|
public string VerificationDate { get; set; }
|
||||||
|
public string CreationDate { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
namespace CompanyManagment.App.Contracts.AuthorizedPerson;
|
||||||
|
|
||||||
|
public class CreateAuthorizedPerson
|
||||||
|
{
|
||||||
|
public string NationalCode { get; set; }
|
||||||
|
public string FirstName { get; set; }
|
||||||
|
public string LastName { get; set; }
|
||||||
|
public string FatherName { get; set; }
|
||||||
|
public string BirthDate { get; set; }
|
||||||
|
public string Gender { get; set; }
|
||||||
|
public string DeathStatus { get; set; }
|
||||||
|
public string ShenasnameSeri { get; set; }
|
||||||
|
public string ShenasnameSerial { get; set; }
|
||||||
|
public string ShenasnamehNumber { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using _0_Framework.Application;
|
||||||
|
|
||||||
|
namespace CompanyManagment.App.Contracts.AuthorizedPerson;
|
||||||
|
|
||||||
|
public interface IAuthorizedPersonApplication
|
||||||
|
{
|
||||||
|
OperationResult Create(CreateAuthorizedPerson command);
|
||||||
|
OperationResult CreateFromUidResponse(CreateAuthorizedPerson command);
|
||||||
|
AuthorizedPersonViewModel GetByNationalCode(string nationalCode);
|
||||||
|
List<AuthorizedPersonViewModel> Search(string nationalCode = null, string firstName = null, string lastName = null);
|
||||||
|
bool ExistsByNationalCode(string nationalCode);
|
||||||
|
}
|
||||||
119
CompanyManagment.Application/AuthorizedPersonApplication.cs
Normal file
119
CompanyManagment.Application/AuthorizedPersonApplication.cs
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using _0_Framework.Application;
|
||||||
|
using Company.Domain.AuthorizedPersonAgg;
|
||||||
|
using CompanyManagment.App.Contracts.AuthorizedPerson;
|
||||||
|
|
||||||
|
namespace CompanyManagment.Application;
|
||||||
|
|
||||||
|
public class AuthorizedPersonApplication : IAuthorizedPersonApplication
|
||||||
|
{
|
||||||
|
private readonly IAuthorizedPersonRepository _authorizedPersonRepository;
|
||||||
|
|
||||||
|
public AuthorizedPersonApplication(IAuthorizedPersonRepository authorizedPersonRepository)
|
||||||
|
{
|
||||||
|
_authorizedPersonRepository = authorizedPersonRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult Create(CreateAuthorizedPerson command)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
|
||||||
|
if (_authorizedPersonRepository.ExistsByNationalCode(command.NationalCode))
|
||||||
|
return operation.Failed("شخص با این کد ملی قبلاً ثبت شده است");
|
||||||
|
|
||||||
|
var authorizedPerson = new AuthorizedPerson(
|
||||||
|
command.NationalCode, command.FirstName, command.LastName,
|
||||||
|
command.FatherName, command.BirthDate, command.Gender,
|
||||||
|
command.DeathStatus, command.ShenasnameSeri,
|
||||||
|
command.ShenasnameSerial, command.ShenasnamehNumber);
|
||||||
|
|
||||||
|
_authorizedPersonRepository.Create(authorizedPerson);
|
||||||
|
_authorizedPersonRepository.SaveChanges();
|
||||||
|
|
||||||
|
return operation.Succcedded();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult CreateFromUidResponse(CreateAuthorizedPerson command)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
|
||||||
|
var existingPerson = _authorizedPersonRepository.GetByNationalCode(command.NationalCode);
|
||||||
|
if (existingPerson != null)
|
||||||
|
{
|
||||||
|
existingPerson.UpdatePersonalInfo(command.FirstName, command.LastName,
|
||||||
|
command.FatherName, command.Gender, command.DeathStatus);
|
||||||
|
_authorizedPersonRepository.SaveChanges();
|
||||||
|
return operation.Succcedded();
|
||||||
|
}
|
||||||
|
|
||||||
|
var authorizedPerson = new AuthorizedPerson(
|
||||||
|
command.NationalCode, command.FirstName, command.LastName,
|
||||||
|
command.FatherName, command.BirthDate, command.Gender,
|
||||||
|
command.DeathStatus, command.ShenasnameSeri,
|
||||||
|
command.ShenasnameSerial, command.ShenasnamehNumber);
|
||||||
|
|
||||||
|
_authorizedPersonRepository.Create(authorizedPerson);
|
||||||
|
_authorizedPersonRepository.SaveChanges();
|
||||||
|
|
||||||
|
return operation.Succcedded();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthorizedPersonViewModel GetByNationalCode(string nationalCode)
|
||||||
|
{
|
||||||
|
var authorizedPerson = _authorizedPersonRepository.GetByNationalCode(nationalCode);
|
||||||
|
if (authorizedPerson == null) return null;
|
||||||
|
|
||||||
|
return new AuthorizedPersonViewModel
|
||||||
|
{
|
||||||
|
Id = authorizedPerson.id,
|
||||||
|
NationalCode = authorizedPerson.NationalCode,
|
||||||
|
FirstName = authorizedPerson.FirstName,
|
||||||
|
LastName = authorizedPerson.LastName,
|
||||||
|
FatherName = authorizedPerson.FatherName,
|
||||||
|
BirthDate = authorizedPerson.BirthDate,
|
||||||
|
Gender = authorizedPerson.Gender,
|
||||||
|
DeathStatus = authorizedPerson.DeathStatus,
|
||||||
|
ShenasnameSeri = authorizedPerson.ShenasnameSeri,
|
||||||
|
ShenasnameSerial = authorizedPerson.ShenasnameSerial,
|
||||||
|
ShenasnamehNumber = authorizedPerson.ShenasnamehNumber,
|
||||||
|
IsVerified = authorizedPerson.IsVerified,
|
||||||
|
VerificationDate = authorizedPerson.VerificationDate?.ToString("yyyy/MM/dd HH:mm"),
|
||||||
|
CreationDate = authorizedPerson.CreationDate.ToString("yyyy/MM/dd HH:mm")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AuthorizedPersonViewModel> Search(string nationalCode = null, string firstName = null, string lastName = null)
|
||||||
|
{
|
||||||
|
var allPersons = _authorizedPersonRepository.Get();
|
||||||
|
|
||||||
|
var filteredPersons = allPersons.Where(x =>
|
||||||
|
(string.IsNullOrEmpty(nationalCode) || x.NationalCode.Contains(nationalCode)) &&
|
||||||
|
(string.IsNullOrEmpty(firstName) || x.FirstName.Contains(firstName)) &&
|
||||||
|
(string.IsNullOrEmpty(lastName) || x.LastName.Contains(lastName)))
|
||||||
|
.Select(x => new AuthorizedPersonViewModel
|
||||||
|
{
|
||||||
|
Id = x.id,
|
||||||
|
NationalCode = x.NationalCode,
|
||||||
|
FirstName = x.FirstName,
|
||||||
|
LastName = x.LastName,
|
||||||
|
FatherName = x.FatherName,
|
||||||
|
BirthDate = x.BirthDate,
|
||||||
|
Gender = x.Gender,
|
||||||
|
DeathStatus = x.DeathStatus,
|
||||||
|
ShenasnameSeri = x.ShenasnameSeri,
|
||||||
|
ShenasnameSerial = x.ShenasnameSerial,
|
||||||
|
ShenasnamehNumber = x.ShenasnamehNumber,
|
||||||
|
IsVerified = x.IsVerified,
|
||||||
|
VerificationDate = x.VerificationDate?.ToString("yyyy/MM/dd HH:mm"),
|
||||||
|
CreationDate = x.CreationDate.ToString("yyyy/MM/dd HH:mm")
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
return filteredPersons;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ExistsByNationalCode(string nationalCode)
|
||||||
|
{
|
||||||
|
return _authorizedPersonRepository.ExistsByNationalCode(nationalCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -118,6 +118,7 @@ using Company.Domain.YearlysSalaryTitleAgg;
|
|||||||
using CompanyManagment.EFCore.Mapping;
|
using CompanyManagment.EFCore.Mapping;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
|
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
|
||||||
|
using Company.Domain.AuthorizedPersonAgg;
|
||||||
using Evidence = Company.Domain.Evidence.Evidence;
|
using Evidence = Company.Domain.Evidence.Evidence;
|
||||||
using Zone = Company.Domain.ZoneAgg.Zone;
|
using Zone = Company.Domain.ZoneAgg.Zone;
|
||||||
|
|
||||||
@@ -194,7 +195,8 @@ public class CompanyContext : DbContext
|
|||||||
|
|
||||||
public DbSet<PaymentInstrument> PaymentInstruments { get; set; }
|
public DbSet<PaymentInstrument> PaymentInstruments { get; set; }
|
||||||
public DbSet<PaymentInstrumentGroup> PaymentInstrumentGroups { get; set; }
|
public DbSet<PaymentInstrumentGroup> PaymentInstrumentGroups { get; set; }
|
||||||
|
public DbSet<AuthorizedPerson> AuthorizedPersons { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Pooya
|
#region Pooya
|
||||||
|
|||||||
60
CompanyManagment.EFCore/Mapping/AuthorizedPersonMapping.cs
Normal file
60
CompanyManagment.EFCore/Mapping/AuthorizedPersonMapping.cs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
using Company.Domain.AuthorizedPersonAgg;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
|
|
||||||
|
namespace CompanyManagment.EFCore.Mapping;
|
||||||
|
|
||||||
|
public class AuthorizedPersonMapping : IEntityTypeConfiguration<AuthorizedPerson>
|
||||||
|
{
|
||||||
|
public void Configure(EntityTypeBuilder<AuthorizedPerson> builder)
|
||||||
|
{
|
||||||
|
builder.ToTable("AuthorizedPersons");
|
||||||
|
|
||||||
|
builder.HasKey(x => x.id);
|
||||||
|
|
||||||
|
builder.Property(x => x.NationalCode)
|
||||||
|
.HasMaxLength(10)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
builder.Property(x => x.FirstName)
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
builder.Property(x => x.LastName)
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
builder.Property(x => x.FatherName)
|
||||||
|
.HasMaxLength(100);
|
||||||
|
|
||||||
|
builder.Property(x => x.BirthDate)
|
||||||
|
.HasMaxLength(10);
|
||||||
|
|
||||||
|
builder.Property(x => x.Gender)
|
||||||
|
.HasMaxLength(50);
|
||||||
|
|
||||||
|
builder.Property(x => x.DeathStatus)
|
||||||
|
.HasMaxLength(50);
|
||||||
|
|
||||||
|
builder.Property(x => x.ShenasnameSeri)
|
||||||
|
.HasMaxLength(10);
|
||||||
|
|
||||||
|
builder.Property(x => x.ShenasnameSerial)
|
||||||
|
.HasMaxLength(10);
|
||||||
|
|
||||||
|
builder.Property(x => x.ShenasnamehNumber)
|
||||||
|
.HasMaxLength(20);
|
||||||
|
|
||||||
|
builder.Property(x => x.IsVerified)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
builder.Property(x => x.VerificationDate);
|
||||||
|
|
||||||
|
builder.Property(x => x.CreationDate)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
// Index for better performance on NationalCode queries
|
||||||
|
builder.HasIndex(x => x.NationalCode)
|
||||||
|
.IsUnique();
|
||||||
|
}
|
||||||
|
}
|
||||||
10555
CompanyManagment.EFCore/Migrations/20250827073456_AddAuthorizedPersonTable.Designer.cs
generated
Normal file
10555
CompanyManagment.EFCore/Migrations/20250827073456_AddAuthorizedPersonTable.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,53 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace CompanyManagment.EFCore.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddAuthorizedPersonTable : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "AuthorizedPersons",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
id = table.Column<long>(type: "bigint", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
NationalCode = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: false),
|
||||||
|
FirstName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||||
|
LastName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||||
|
FatherName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
|
||||||
|
BirthDate = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: true),
|
||||||
|
Gender = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
|
||||||
|
DeathStatus = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
|
||||||
|
ShenasnameSeri = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: true),
|
||||||
|
ShenasnameSerial = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: true),
|
||||||
|
ShenasnamehNumber = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true),
|
||||||
|
IsVerified = table.Column<bool>(type: "bit", nullable: false),
|
||||||
|
VerificationDate = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||||
|
CreationDate = table.Column<DateTime>(type: "datetime2", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_AuthorizedPersons", x => x.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_AuthorizedPersons_NationalCode",
|
||||||
|
table: "AuthorizedPersons",
|
||||||
|
column: "NationalCode",
|
||||||
|
unique: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "AuthorizedPersons");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -90,6 +90,74 @@ namespace CompanyManagment.EFCore.Migrations
|
|||||||
b.ToTable("AndroidApkVersions", (string)null);
|
b.ToTable("AndroidApkVersions", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Company.Domain.AuthorizedPersonAgg.AuthorizedPerson", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("id"));
|
||||||
|
|
||||||
|
b.Property<string>("BirthDate")
|
||||||
|
.HasMaxLength(10)
|
||||||
|
.HasColumnType("nvarchar(10)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreationDate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<string>("DeathStatus")
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("nvarchar(50)");
|
||||||
|
|
||||||
|
b.Property<string>("FatherName")
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("nvarchar(100)");
|
||||||
|
|
||||||
|
b.Property<string>("FirstName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("nvarchar(100)");
|
||||||
|
|
||||||
|
b.Property<string>("Gender")
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("nvarchar(50)");
|
||||||
|
|
||||||
|
b.Property<bool>("IsVerified")
|
||||||
|
.HasColumnType("bit");
|
||||||
|
|
||||||
|
b.Property<string>("LastName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("nvarchar(100)");
|
||||||
|
|
||||||
|
b.Property<string>("NationalCode")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(10)
|
||||||
|
.HasColumnType("nvarchar(10)");
|
||||||
|
|
||||||
|
b.Property<string>("ShenasnameSeri")
|
||||||
|
.HasMaxLength(10)
|
||||||
|
.HasColumnType("nvarchar(10)");
|
||||||
|
|
||||||
|
b.Property<string>("ShenasnameSerial")
|
||||||
|
.HasMaxLength(10)
|
||||||
|
.HasColumnType("nvarchar(10)");
|
||||||
|
|
||||||
|
b.Property<string>("ShenasnamehNumber")
|
||||||
|
.HasMaxLength(20)
|
||||||
|
.HasColumnType("nvarchar(20)");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("VerificationDate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.HasKey("id");
|
||||||
|
|
||||||
|
b.HasIndex("NationalCode")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("AuthorizedPersons", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Company.Domain.BankAgg.Bank", b =>
|
modelBuilder.Entity("Company.Domain.BankAgg.Bank", b =>
|
||||||
{
|
{
|
||||||
b.Property<long>("id")
|
b.Property<long>("id")
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using Company.Domain.AuthorizedPersonAgg;
|
||||||
|
using _0_Framework.InfraStructure;
|
||||||
|
using CompanyManagment.EFCore;
|
||||||
|
|
||||||
|
namespace CompanyManagment.EFCore.Repository;
|
||||||
|
|
||||||
|
public class AuthorizedPersonRepository : RepositoryBase<long, AuthorizedPerson>, IAuthorizedPersonRepository
|
||||||
|
{
|
||||||
|
private readonly CompanyContext _context;
|
||||||
|
|
||||||
|
public AuthorizedPersonRepository(CompanyContext context) : base(context)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthorizedPerson GetByNationalCode(string nationalCode)
|
||||||
|
{
|
||||||
|
return _context.AuthorizedPersons
|
||||||
|
.FirstOrDefault(x => x.NationalCode == nationalCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ExistsByNationalCode(string nationalCode)
|
||||||
|
{
|
||||||
|
return _context.AuthorizedPersons
|
||||||
|
.Any(x => x.NationalCode == nationalCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
142
CompanyManagment.EFCore/Services/UidService.cs
Normal file
142
CompanyManagment.EFCore/Services/UidService.cs
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
using System;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Json;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using CompanyManagment.App.Contracts.AuthorizedPerson;
|
||||||
|
using _0_Framework.Application;
|
||||||
|
using _0_Framework.Application.UID;
|
||||||
|
|
||||||
|
namespace CompanyManagment.EFCore.Services;
|
||||||
|
|
||||||
|
public class UidService : IUidService
|
||||||
|
{
|
||||||
|
private readonly HttpClient _httpClient;
|
||||||
|
private readonly IAuthorizedPersonApplication _authorizedPersonApplication;
|
||||||
|
private const string BaseUrl = "https://json-api.uid.ir/api/inquiry/";
|
||||||
|
|
||||||
|
public UidService(IAuthorizedPersonApplication authorizedPersonApplication)
|
||||||
|
{
|
||||||
|
_httpClient = new HttpClient()
|
||||||
|
{
|
||||||
|
BaseAddress = new Uri(BaseUrl)
|
||||||
|
};
|
||||||
|
_authorizedPersonApplication = authorizedPersonApplication;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<PersonalInfoResponse> GetPersonalInfo(string nationalCode, string birthDate)
|
||||||
|
{
|
||||||
|
// First check if person exists in database
|
||||||
|
var existingPerson = _authorizedPersonApplication.GetByNationalCode(nationalCode);
|
||||||
|
if (existingPerson != null)
|
||||||
|
{
|
||||||
|
// Return data from database instead of calling API
|
||||||
|
return CreatePersonalInfoResponseFromDatabase(existingPerson);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If not found in database, call UID API
|
||||||
|
var request = new PersonalInfoRequest
|
||||||
|
{
|
||||||
|
BirthDate = birthDate,
|
||||||
|
NationalId = nationalCode,
|
||||||
|
RequestContext = new UidRequestContext()
|
||||||
|
};
|
||||||
|
var json = JsonConvert.SerializeObject(request);
|
||||||
|
var contentType = new StringContent(json, Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var requestResult = await _httpClient.PostAsync("person/v2", contentType);
|
||||||
|
if (!requestResult.IsSuccessStatusCode)
|
||||||
|
return null;
|
||||||
|
var responseResult = await requestResult.Content.ReadFromJsonAsync<PersonalInfoResponse>();
|
||||||
|
if (responseResult.BasicInformation != null)
|
||||||
|
{
|
||||||
|
responseResult.BasicInformation.FirstName = responseResult.BasicInformation.FirstName?.ToPersian();
|
||||||
|
responseResult.BasicInformation.LastName = responseResult.BasicInformation.LastName?.ToPersian();
|
||||||
|
responseResult.BasicInformation.FatherName = responseResult.BasicInformation.FatherName?.ToPersian();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ذخیره اطلاعات در جدول AuthorizedPerson
|
||||||
|
await SaveAuthorizedPersonData(responseResult, nationalCode, birthDate);
|
||||||
|
|
||||||
|
return responseResult;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return new PersonalInfoResponse(new UidBasicInformation(),
|
||||||
|
new IdentificationInformation(default, default, default, default, default), new RegistrationStatus(),
|
||||||
|
new ResponseContext(new UidStatus(14, "")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private PersonalInfoResponse CreatePersonalInfoResponseFromDatabase(AuthorizedPersonViewModel person)
|
||||||
|
{
|
||||||
|
var basicInfo = new UidBasicInformation
|
||||||
|
{
|
||||||
|
FirstName = person.FirstName,
|
||||||
|
LastName = person.LastName,
|
||||||
|
FatherName = person.FatherName,
|
||||||
|
Gender = person.Gender
|
||||||
|
};
|
||||||
|
|
||||||
|
var identificationInfo = new IdentificationInformation(
|
||||||
|
person.NationalCode,
|
||||||
|
person.BirthDate,
|
||||||
|
person.ShenasnameSeri,
|
||||||
|
person.ShenasnameSerial,
|
||||||
|
person.ShenasnamehNumber
|
||||||
|
);
|
||||||
|
|
||||||
|
var registrationStatus = new RegistrationStatus
|
||||||
|
{
|
||||||
|
DeathStatus = person.DeathStatus
|
||||||
|
};
|
||||||
|
|
||||||
|
var responseContext = new ResponseContext(new UidStatus(0, "Success - از دیتابیس"));
|
||||||
|
|
||||||
|
return new PersonalInfoResponse(basicInfo, identificationInfo, registrationStatus, responseContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SaveAuthorizedPersonData(PersonalInfoResponse response, string nationalCode, string birthDate)
|
||||||
|
{
|
||||||
|
if (response?.BasicInformation == null || response.ResponseContext?.Status?.Code != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var command = new CreateAuthorizedPerson
|
||||||
|
{
|
||||||
|
NationalCode = nationalCode,
|
||||||
|
FirstName = response.BasicInformation.FirstName ?? "",
|
||||||
|
LastName = response.BasicInformation.LastName ?? "",
|
||||||
|
FatherName = response.BasicInformation.FatherName ?? "",
|
||||||
|
BirthDate = birthDate,
|
||||||
|
Gender = response.BasicInformation.Gender ?? "",
|
||||||
|
DeathStatus = response.RegistrationStatus?.DeathStatus ?? "",
|
||||||
|
ShenasnameSeri = response.IdentificationInformation?.ShenasnameSeri ?? "",
|
||||||
|
ShenasnameSerial = response.IdentificationInformation?.ShenasnameSerial ?? "",
|
||||||
|
ShenasnamehNumber = response.IdentificationInformation?.ShenasnamehNumber ?? ""
|
||||||
|
};
|
||||||
|
|
||||||
|
_authorizedPersonApplication.CreateFromUidResponse(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<MatchMobileWithNationalCodeResponse> IsMachPhoneWithNationalCode(string nationalCode, string phoneNumber)
|
||||||
|
{
|
||||||
|
var request = new PersonalInfoRequest
|
||||||
|
{
|
||||||
|
MobileNumber = phoneNumber,
|
||||||
|
NationalId = nationalCode,
|
||||||
|
RequestContext = new UidRequestContext()
|
||||||
|
};
|
||||||
|
var json = JsonConvert.SerializeObject(request);
|
||||||
|
var contentType = new StringContent(json, Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
|
var requestResult = await _httpClient.PostAsync("mobile/owner/v2", contentType);
|
||||||
|
if (!requestResult.IsSuccessStatusCode)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var responseResult = await requestResult.Content.ReadFromJsonAsync<MatchMobileWithNationalCodeResponse>();
|
||||||
|
return responseResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using _0_Framework.Application.UID;
|
||||||
using Company.Domain.BillAgg;
|
using Company.Domain.BillAgg;
|
||||||
using Company.Domain.Board;
|
using Company.Domain.Board;
|
||||||
using Company.Domain.ChapterAgg;
|
using Company.Domain.ChapterAgg;
|
||||||
@@ -216,6 +217,9 @@ using CompanyManagment.App.Contracts.AdminMonthlyOverview;
|
|||||||
using CompanyManagment.App.Contracts.ContractingPartyBankAccounts;
|
using CompanyManagment.App.Contracts.ContractingPartyBankAccounts;
|
||||||
using CompanyManagment.App.Contracts.PaymentInstrument;
|
using CompanyManagment.App.Contracts.PaymentInstrument;
|
||||||
using CompanyManagment.App.Contracts.PaymentTransaction;
|
using CompanyManagment.App.Contracts.PaymentTransaction;
|
||||||
|
using CompanyManagment.App.Contracts.AuthorizedPerson;
|
||||||
|
using Company.Domain.AuthorizedPersonAgg;
|
||||||
|
using CompanyManagment.EFCore.Repository;
|
||||||
|
|
||||||
namespace PersonalContractingParty.Config;
|
namespace PersonalContractingParty.Config;
|
||||||
|
|
||||||
@@ -300,6 +304,13 @@ public class PersonalBootstrapper
|
|||||||
services.AddTransient<IInstitutionContractApplication, InstitutionContractApplication>();
|
services.AddTransient<IInstitutionContractApplication, InstitutionContractApplication>();
|
||||||
services.AddTransient<IInstitutionContractRepository, InstitutionContractRepository>();
|
services.AddTransient<IInstitutionContractRepository, InstitutionContractRepository>();
|
||||||
|
|
||||||
|
// AuthorizedPerson Services
|
||||||
|
services.AddTransient<IAuthorizedPersonApplication, AuthorizedPersonApplication>();
|
||||||
|
services.AddTransient<IAuthorizedPersonRepository, AuthorizedPersonRepository>();
|
||||||
|
|
||||||
|
// UID Service - moved to Infrastructure layer
|
||||||
|
services.AddTransient<IUidService, CompanyManagment.EFCore.Services.UidService>();
|
||||||
|
|
||||||
services.AddTransient<IContactInfoApplication, InstitutionContractContactInfoApplication>();
|
services.AddTransient<IContactInfoApplication, InstitutionContractContactInfoApplication>();
|
||||||
services.AddTransient<IContactInfoRepository, InstitutionContractContactInfoRepository>();
|
services.AddTransient<IContactInfoRepository, InstitutionContractContactInfoRepository>();
|
||||||
|
|
||||||
@@ -576,4 +587,4 @@ public class PersonalBootstrapper
|
|||||||
|
|
||||||
services.AddDbContext<CompanyContext>(x => x.UseSqlServer(connectionString));
|
services.AddDbContext<CompanyContext>(x => x.UseSqlServer(connectionString));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ using Microsoft.OpenApi.Models;
|
|||||||
using ServiceHost.Test;
|
using ServiceHost.Test;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using CompanyManagment.EFCore.Services;
|
||||||
using Microsoft.AspNetCore.CookiePolicy;
|
using Microsoft.AspNetCore.CookiePolicy;
|
||||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|||||||
Reference in New Issue
Block a user