This commit is contained in:
Thanakarn Klangkasame
2025-09-30 11:01:02 +07:00
commit 92e614674c
182 changed files with 9596 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
using System.Data;
using AMREZ.EOP.Abstractions.Applications.Tenancy;
using AMREZ.EOP.Abstractions.Applications.UseCases.HumanResources;
using AMREZ.EOP.Abstractions.Infrastructures.Common;
using AMREZ.EOP.Abstractions.Infrastructures.Repositories;
using AMREZ.EOP.Contracts.DTOs.HumanResources.EmergencyContact;
using AMREZ.EOP.Contracts.DTOs.HumanResources.EmergencyContactAdd;
using AMREZ.EOP.Domain.Entities.HumanResources;
using Microsoft.AspNetCore.Http;
namespace AMREZ.EOP.Application.UseCases.HumanResources;
public sealed class AddEmergencyContactUseCase : IAddEmergencyContactUseCase
{
private readonly ITenantResolver _resolver;
private readonly IUnitOfWork _uow;
private readonly IUserProfileRepository _hr;
private readonly IHttpContextAccessor _http;
public AddEmergencyContactUseCase(ITenantResolver r, IUnitOfWork uow, IUserProfileRepository hr, IHttpContextAccessor http)
{ _resolver = r; _uow = uow; _hr = hr; _http = http; }
public async Task<EmergencyContactResponse?> ExecuteAsync(EmergencyContactAddRequest request, CancellationToken ct = default)
{
var http = _http.HttpContext ?? throw new InvalidOperationException("No HttpContext");
var tenant = _resolver.Resolve(http, request);
if (tenant is null) return null;
await _uow.BeginAsync(tenant, IsolationLevel.ReadCommitted, ct);
try
{
var ec = new EmergencyContact
{
UserProfileId = request.UserProfileId,
Name = request.Name,
Relationship = request.Relationship,
Phone = request.Phone,
Email = request.Email,
IsPrimary = request.IsPrimary
};
var added = await _hr.AddEmergencyContactAsync(ec, ct);
if (request.IsPrimary)
await _hr.SetPrimaryEmergencyContactAsync(request.UserProfileId, added.Id, ct);
await _uow.CommitAsync(ct);
return new EmergencyContactResponse(added.Id, added.UserProfileId, added.IsPrimary);
}
catch { await _uow.RollbackAsync(ct); throw; }
}
}

View File

@@ -0,0 +1,65 @@
using System.Data;
using AMREZ.EOP.Abstractions.Applications.Tenancy;
using AMREZ.EOP.Abstractions.Applications.UseCases.HumanResources;
using AMREZ.EOP.Abstractions.Infrastructures.Common;
using AMREZ.EOP.Abstractions.Infrastructures.Repositories;
using AMREZ.EOP.Contracts.DTOs.HumanResources.EmployeeAddress;
using AMREZ.EOP.Contracts.DTOs.HumanResources.EmployeeAddressAdd;
using AMREZ.EOP.Domain.Entities.HumanResources;
using Microsoft.AspNetCore.Http;
namespace AMREZ.EOP.Application.UseCases.HumanResources;
public sealed class AddEmployeeAddressUseCase : IAddEmployeeAddressUseCase
{
private readonly ITenantResolver _resolver;
private readonly IUnitOfWork _uow;
private readonly IUserProfileRepository _hr;
private readonly IHttpContextAccessor _http;
public AddEmployeeAddressUseCase(ITenantResolver r, IUnitOfWork uow, IUserProfileRepository hr,
IHttpContextAccessor http)
{
_resolver = r;
_uow = uow;
_hr = hr;
_http = http;
}
public async Task<EmployeeAddressResponse?> ExecuteAsync(EmployeeAddressAddRequest request,
CancellationToken ct = default)
{
var http = _http.HttpContext ?? throw new InvalidOperationException("No HttpContext");
var tenant = _resolver.Resolve(http, request);
if (tenant is null) return null;
await _uow.BeginAsync(tenant, IsolationLevel.ReadCommitted, ct);
try
{
var addr = new EmployeeAddress
{
UserProfileId = request.UserProfileId,
Type = request.Type,
Line1 = request.Line1,
Line2 = request.Line2,
City = request.City,
State = request.State,
PostalCode = request.PostalCode,
Country = request.Country,
IsPrimary = request.IsPrimary
};
var added = await _hr.AddAddressAsync(addr, ct);
if (request.IsPrimary)
await _hr.SetPrimaryAddressAsync(request.UserProfileId, added.Id, ct);
await _uow.CommitAsync(ct);
return new EmployeeAddressResponse(added.Id, added.UserProfileId, added.IsPrimary);
}
catch
{
await _uow.RollbackAsync(ct);
throw;
}
}
}

View File

@@ -0,0 +1,63 @@
using System.Data;
using AMREZ.EOP.Abstractions.Applications.Tenancy;
using AMREZ.EOP.Abstractions.Applications.UseCases.HumanResources;
using AMREZ.EOP.Abstractions.Infrastructures.Common;
using AMREZ.EOP.Abstractions.Infrastructures.Repositories;
using AMREZ.EOP.Contracts.DTOs.HumanResources.EmployeeBankAccount;
using AMREZ.EOP.Contracts.DTOs.HumanResources.EmployeeBankAccountAdd;
using AMREZ.EOP.Domain.Entities.HumanResources;
using Microsoft.AspNetCore.Http;
namespace AMREZ.EOP.Application.UseCases.HumanResources;
public sealed class AddEmployeeBankAccountUseCase : IAddEmployeeBankAccountUseCase
{
private readonly ITenantResolver _resolver;
private readonly IUnitOfWork _uow;
private readonly IUserProfileRepository _hr;
private readonly IHttpContextAccessor _http;
public AddEmployeeBankAccountUseCase(ITenantResolver r, IUnitOfWork uow, IUserProfileRepository hr,
IHttpContextAccessor http)
{
_resolver = r;
_uow = uow;
_hr = hr;
_http = http;
}
public async Task<EmployeeBankAccountResponse?> ExecuteAsync(EmployeeBankAccountAddRequest request,
CancellationToken ct = default)
{
var http = _http.HttpContext ?? throw new InvalidOperationException("No HttpContext");
var tenant = _resolver.Resolve(http, request);
if (tenant is null) return null;
await _uow.BeginAsync(tenant, IsolationLevel.ReadCommitted, ct);
try
{
var b = new EmployeeBankAccount
{
UserProfileId = request.UserProfileId,
BankName = request.BankName,
AccountNumber = request.AccountNumber,
AccountHolder = request.AccountHolder,
Branch = request.Branch,
Note = request.Note,
IsPrimary = request.IsPrimary
};
var added = await _hr.AddBankAccountAsync(b, ct);
if (request.IsPrimary)
await _hr.SetPrimaryBankAccountAsync(request.UserProfileId, added.Id, ct);
await _uow.CommitAsync(ct);
return new EmployeeBankAccountResponse(added.Id, added.UserProfileId, added.IsPrimary);
}
catch
{
await _uow.RollbackAsync(ct);
throw;
}
}
}

View File

@@ -0,0 +1,60 @@
using System.Data;
using AMREZ.EOP.Abstractions.Applications.Tenancy;
using AMREZ.EOP.Abstractions.Applications.UseCases.HumanResources;
using AMREZ.EOP.Abstractions.Infrastructures.Common;
using AMREZ.EOP.Abstractions.Infrastructures.Repositories;
using AMREZ.EOP.Contracts.DTOs.HumanResources.Employment;
using AMREZ.EOP.Contracts.DTOs.HumanResources.EmploymentAdd;
using AMREZ.EOP.Domain.Entities.HumanResources;
using Microsoft.AspNetCore.Http;
namespace AMREZ.EOP.Application.UseCases.HumanResources;
public sealed class AddEmploymentUseCase : IAddEmploymentUseCase
{
private readonly ITenantResolver _resolver;
private readonly IUnitOfWork _uow;
private readonly IUserProfileRepository _hr;
private readonly IHttpContextAccessor _http;
public AddEmploymentUseCase(ITenantResolver r, IUnitOfWork uow, IUserProfileRepository hr,
IHttpContextAccessor http)
{
_resolver = r;
_uow = uow;
_hr = hr;
_http = http;
}
public async Task<EmploymentResponse?> ExecuteAsync(EmploymentAddRequest request, CancellationToken ct = default)
{
var http = _http.HttpContext ?? throw new InvalidOperationException("No HttpContext");
var tenant = _resolver.Resolve(http, request);
if (tenant is null) return null;
await _uow.BeginAsync(tenant, IsolationLevel.ReadCommitted, ct);
try
{
var e = new Employment
{
UserProfileId = request.UserProfileId,
EmploymentType = request.EmploymentType,
StartDate = request.StartDate,
DepartmentId = request.DepartmentId,
PositionId = request.PositionId,
ManagerUserId = request.ManagerUserId,
WorkEmail = request.WorkEmail,
WorkPhone = request.WorkPhone
};
var added = await _hr.AddEmploymentAsync(e, ct);
await _uow.CommitAsync(ct);
return new EmploymentResponse(added.Id, added.UserProfileId, added.StartDate, added.EndDate);
}
catch
{
await _uow.RollbackAsync(ct);
throw;
}
}
}

View File

@@ -0,0 +1,46 @@
using System.Data;
using AMREZ.EOP.Abstractions.Applications.Tenancy;
using AMREZ.EOP.Abstractions.Applications.UseCases.HumanResources;
using AMREZ.EOP.Abstractions.Infrastructures.Common;
using AMREZ.EOP.Abstractions.Infrastructures.Repositories;
using AMREZ.EOP.Contracts.DTOs.HumanResources.EmploymentEnd;
using Microsoft.AspNetCore.Http;
namespace AMREZ.EOP.Application.UseCases.HumanResources;
public sealed class EndEmploymentUseCase : IEndEmploymentUseCase
{
private readonly ITenantResolver _resolver;
private readonly IUnitOfWork _uow;
private readonly IUserProfileRepository _hr;
private readonly IHttpContextAccessor _http;
public EndEmploymentUseCase(ITenantResolver r, IUnitOfWork uow, IUserProfileRepository hr,
IHttpContextAccessor http)
{
_resolver = r;
_uow = uow;
_hr = hr;
_http = http;
}
public async Task<bool> ExecuteAsync(EmploymentEndRequest request, CancellationToken ct = default)
{
var http = _http.HttpContext ?? throw new InvalidOperationException("No HttpContext");
var tenant = _resolver.Resolve(http, request);
if (tenant is null) return false;
await _uow.BeginAsync(tenant, IsolationLevel.ReadCommitted, ct);
try
{
await _hr.EndEmploymentAsync(request.EmploymentId, request.EndDate, ct);
await _uow.CommitAsync(ct);
return true;
}
catch
{
await _uow.RollbackAsync(ct);
throw;
}
}
}

View File

@@ -0,0 +1,46 @@
using System.Data;
using AMREZ.EOP.Abstractions.Applications.Tenancy;
using AMREZ.EOP.Abstractions.Applications.UseCases.HumanResources;
using AMREZ.EOP.Abstractions.Infrastructures.Common;
using AMREZ.EOP.Abstractions.Infrastructures.Repositories;
using AMREZ.EOP.Contracts.DTOs.HumanResources.SetPrimaryAddress;
using Microsoft.AspNetCore.Http;
namespace AMREZ.EOP.Application.UseCases.HumanResources;
public sealed class SetPrimaryAddressUseCase : ISetPrimaryAddressUseCase
{
private readonly ITenantResolver _resolver;
private readonly IUnitOfWork _uow;
private readonly IUserProfileRepository _hr;
private readonly IHttpContextAccessor _http;
public SetPrimaryAddressUseCase(ITenantResolver r, IUnitOfWork uow, IUserProfileRepository hr,
IHttpContextAccessor http)
{
_resolver = r;
_uow = uow;
_hr = hr;
_http = http;
}
public async Task<bool> ExecuteAsync(SetPrimaryAddressRequest request, CancellationToken ct = default)
{
var http = _http.HttpContext ?? throw new InvalidOperationException("No HttpContext");
var tenant = _resolver.Resolve(http, request);
if (tenant is null) return false;
await _uow.BeginAsync(tenant, IsolationLevel.ReadCommitted, ct);
try
{
await _hr.SetPrimaryAddressAsync(request.UserProfileId, request.AddressId, ct);
await _uow.CommitAsync(ct);
return true;
}
catch
{
await _uow.RollbackAsync(ct);
throw;
}
}
}

View File

@@ -0,0 +1,46 @@
using System.Data;
using AMREZ.EOP.Abstractions.Applications.Tenancy;
using AMREZ.EOP.Abstractions.Applications.UseCases.HumanResources;
using AMREZ.EOP.Abstractions.Infrastructures.Common;
using AMREZ.EOP.Abstractions.Infrastructures.Repositories;
using AMREZ.EOP.Contracts.DTOs.HumanResources.SetPrimaryBankAccount;
using Microsoft.AspNetCore.Http;
namespace AMREZ.EOP.Application.UseCases.HumanResources;
public sealed class SetPrimaryBankAccountUseCase : ISetPrimaryBankAccountUseCase
{
private readonly ITenantResolver _resolver;
private readonly IUnitOfWork _uow;
private readonly IUserProfileRepository _hr;
private readonly IHttpContextAccessor _http;
public SetPrimaryBankAccountUseCase(ITenantResolver r, IUnitOfWork uow, IUserProfileRepository hr,
IHttpContextAccessor http)
{
_resolver = r;
_uow = uow;
_hr = hr;
_http = http;
}
public async Task<bool> ExecuteAsync(SetPrimaryBankAccountRequest request, CancellationToken ct = default)
{
var http = _http.HttpContext ?? throw new InvalidOperationException("No HttpContext");
var tenant = _resolver.Resolve(http, request);
if (tenant is null) return false;
await _uow.BeginAsync(tenant, IsolationLevel.ReadCommitted, ct);
try
{
await _hr.SetPrimaryBankAccountAsync(request.UserProfileId, request.BankAccountId, ct);
await _uow.CommitAsync(ct);
return true;
}
catch
{
await _uow.RollbackAsync(ct);
throw;
}
}
}

View File

@@ -0,0 +1,46 @@
using System.Data;
using AMREZ.EOP.Abstractions.Applications.Tenancy;
using AMREZ.EOP.Abstractions.Applications.UseCases.HumanResources;
using AMREZ.EOP.Abstractions.Infrastructures.Common;
using AMREZ.EOP.Abstractions.Infrastructures.Repositories;
using AMREZ.EOP.Contracts.DTOs.HumanResources.SetPrimaryEmergencyContact;
using Microsoft.AspNetCore.Http;
namespace AMREZ.EOP.Application.UseCases.HumanResources;
public sealed class SetPrimaryEmergencyContactUseCase : ISetPrimaryEmergencyContactUseCase
{
private readonly ITenantResolver _resolver;
private readonly IUnitOfWork _uow;
private readonly IUserProfileRepository _hr;
private readonly IHttpContextAccessor _http;
public SetPrimaryEmergencyContactUseCase(ITenantResolver r, IUnitOfWork uow, IUserProfileRepository hr,
IHttpContextAccessor http)
{
_resolver = r;
_uow = uow;
_hr = hr;
_http = http;
}
public async Task<bool> ExecuteAsync(SetPrimaryEmergencyContactRequest request, CancellationToken ct = default)
{
var http = _http.HttpContext ?? throw new InvalidOperationException("No HttpContext");
var tenant = _resolver.Resolve(http, request);
if (tenant is null) return false;
await _uow.BeginAsync(tenant, IsolationLevel.ReadCommitted, ct);
try
{
await _hr.SetPrimaryEmergencyContactAsync(request.UserProfileId, request.ContactId, ct);
await _uow.CommitAsync(ct);
return true;
}
catch
{
await _uow.RollbackAsync(ct);
throw;
}
}
}

View File

@@ -0,0 +1,59 @@
using System.Data;
using AMREZ.EOP.Abstractions.Applications.Tenancy;
using AMREZ.EOP.Abstractions.Applications.UseCases.HumanResources;
using AMREZ.EOP.Abstractions.Infrastructures.Common;
using AMREZ.EOP.Abstractions.Infrastructures.Repositories;
using AMREZ.EOP.Contracts.DTOs.HumanResources.UserProfile;
using AMREZ.EOP.Contracts.DTOs.HumanResources.UserProfileUpsert;
using AMREZ.EOP.Domain.Entities.HumanResources;
using Microsoft.AspNetCore.Http;
namespace AMREZ.EOP.Application.UseCases.HumanResources;
public sealed class UpsertUserProfileUseCase : IUpsertUserProfileUseCase
{
private readonly ITenantResolver _resolver;
private readonly IUnitOfWork _uow;
private readonly IUserProfileRepository _hr;
private readonly IHttpContextAccessor _http;
public UpsertUserProfileUseCase(ITenantResolver r, IUnitOfWork uow, IUserProfileRepository hr,
IHttpContextAccessor http)
{
_resolver = r;
_uow = uow;
_hr = hr;
_http = http;
}
public async Task<UserProfileResponse?> ExecuteAsync(UserProfileUpsertRequest request,
CancellationToken ct = default)
{
var http = _http.HttpContext ?? throw new InvalidOperationException("No HttpContext");
var tenant = _resolver.Resolve(http, request);
if (tenant is null) return null;
await _uow.BeginAsync(tenant, IsolationLevel.ReadCommitted, ct);
try
{
var current = await _hr.GetByUserIdAsync(request.UserId, ct);
var entity = current ?? new UserProfile { UserId = request.UserId };
entity.FirstName = request.FirstName;
entity.LastName = request.LastName;
entity.MiddleName = request.MiddleName;
entity.Nickname = request.Nickname;
entity.DateOfBirth = request.DateOfBirth;
entity.Gender = request.Gender;
await _hr.UpsertAsync(entity, ct);
await _uow.CommitAsync(ct);
return new UserProfileResponse(entity.Id, entity.UserId, entity.FirstName, entity.LastName);
}
catch
{
await _uow.RollbackAsync(ct);
throw;
}
}
}