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