Add employer workflow registration edit and delete functionality

This commit is contained in:
MahanCh
2025-09-11 12:58:50 +03:30
parent 5a1d2640c3
commit 604ac76a1a
3 changed files with 221 additions and 3 deletions

View File

@@ -129,7 +129,22 @@ public interface IEmployerApplication
#endregion
Task<OperationResult> CreateWorkflowRegistration(CreateEmployerWorkflowRegistration command);
Task<OperationResult<AuthenticateUserViewModel>> AuthenticateEmployer(string nationalCode, string dateOfBirth, string mobile);
/// <summary>
/// ویرایش کارفرما در گردش کار ثبت نام
/// </summary>
/// <param name="command"></param>
/// <returns></returns>
Task<OperationResult> EditWorkflowRegistration(EditEmployerWorkflowRegistration command);
/// <summary>
/// حذف کارفرما از گردش کار ثبت نام
/// </summary>
/// <param name="employerId">شناسه کارفرما</param>
/// <param name="institutionWorkshopDetailsId">شناسه جزئیات کارگاه موسسه</param>
/// <returns></returns>
Task<OperationResult> DeleteWorkflowRegistration(long employerId, long institutionWorkshopDetailsId);
Task<OperationResult<AuthenticateUserViewModel>> AuthenticateEmployer(string nationalCode, string dateOfBirth, string mobile);
}
public class AuthenticateUserViewModel
@@ -384,4 +399,15 @@ public class CreateRealEmployerWorkflowRegistration
/// شماره تلفن
/// </summary>
public string Telephone { get; set; }
}
}
/// <summary>
/// کلاس ویرایش کارفرما در گردش کار - شامل اطلاعات کارفرمای حقیقی و حقوقی
/// </summary>
public class EditEmployerWorkflowRegistration : CreateEmployerWorkflowRegistration
{
/// <summary>
/// شناسه کارفرما
/// </summary>
public long EmployerId { get; set; }
}

View File

@@ -41,6 +41,8 @@ public class EmployerApplication : IEmployerApplication
_uidService = uidService;
}
public OperationResult Active(long id)
{
var opration = new OperationResult();
@@ -834,6 +836,15 @@ public class EmployerApplication : IEmployerApplication
nationalCodValid = false;
return opration.Failed("لطفا کد ملی 10 رقمی وارد کنید");
}
if (_EmployerRepository.Exists(x =>
x.Nationalcode == command.Nationalcode && !string.IsNullOrWhiteSpace(command.Nationalcode) &&
x.id != command.Id))
{
nationalcodeIsOk = false;
return opration.Failed(" کد ملی وارد شده تکراری است");
}
}
@@ -1018,7 +1029,7 @@ public class EmployerApplication : IEmployerApplication
}
#endregion
#region Api
public async Task<List<GetEmployerListViewModel>> GetEmployerList(GetEmployerSearchModel searchModel)
@@ -1320,6 +1331,66 @@ public class EmployerApplication : IEmployerApplication
return operation.Succcedded();
}
public async Task<OperationResult> EditWorkflowRegistration(EditEmployerWorkflowRegistration command)
{
var operation = new OperationResult();
// Get the existing employer
var employer = _EmployerRepository.Get(command.EmployerId);
if (employer == null)
return operation.Failed("کارفرمای مورد نظر یافت نشد");
OperationResult editEmployerResult = command.LegalType switch
{
LegalType.Real => await EditRealEmployerRegistration(command.RealEmployer, command.EmployerId),
LegalType.Legal => await EditLegalEmployerRegistration(command.LegalEmployer, command.EmployerId),
_ => throw new ArgumentOutOfRangeException()
};
if (!editEmployerResult.IsSuccedded)
return operation.Failed(editEmployerResult.Message);
await _institutionContractRepository.SaveChangesAsync();
return operation.Succcedded();
}
/// <summary>
/// حذف کارفرما از گردش کار ثبت نام
/// </summary>
/// <param name="employerId">شناسه کارفرما</param>
/// <param name="institutionWorkshopDetailsId">شناسه جزئیات کارگاه موسسه</param>
/// <returns></returns>
public async Task<OperationResult> DeleteWorkflowRegistration(long employerId, long institutionWorkshopDetailsId)
{
var operation = new OperationResult();
// Check if employer exists
var employer = _EmployerRepository.Get(employerId);
if (employer == null)
return operation.Failed("کارفرمای مورد نظر یافت نشد");
// Get workshop details
var workshopDetails = await _institutionContractRepository.GetInstitutionWorkshopDetails(institutionWorkshopDetailsId);
if (workshopDetails == null)
return operation.Failed("جزئیات کارگاه موسسه یافت نشد");
// Find and remove the employer from workshop details
var employerDetail = workshopDetails.Employers.FirstOrDefault(e => e.EmployerId == employerId);
if (employerDetail == null)
return operation.Failed("کارفرما در لیست کارگاه یافت نشد");
// Remove the employer from the list
workshopDetails.Employers.Remove(employerDetail);
await _institutionContractRepository.SaveChangesAsync();
// Delete the employer
_EmployerRepository.Remove(employerId);
await _EmployerRepository.SaveChangesAsync();
return operation.Succcedded();
}
public async Task<OperationResult<AuthenticateUserViewModel>> AuthenticateEmployer(string nationalCode,
string dateOfBirth,
string mobile)
@@ -1491,5 +1562,107 @@ public class EmployerApplication : IEmployerApplication
return opration.Succcedded(employerData);
}
private async Task<OperationResult> EditRealEmployerRegistration(
CreateRealEmployerWorkflowRegistration command, long employerId)
{
var operation = new OperationResult();
var employer = _EmployerRepository.Get(employerId);
if (employer == null)
return operation.Failed("رکورد مورد نظر یافت نشد");
if (_EmployerRepository.Exists(x =>
(x.FName == command.FName && x.LName == command.LName) && x.Nationalcode == command.NationalCode &&
x.id != employerId))
return operation.Failed("امکان ثبت رکورد تکراری وجود ندارد");
if (!string.IsNullOrWhiteSpace(command.NationalCode))
{
if (command.NationalCode.NationalCodeValid() != "valid")
{
return operation.Failed("کد ملی وارد شده نا معتبر است");
}
}
if (_EmployerRepository.Exists(x =>
x.Nationalcode == command.NationalCode && !string.IsNullOrWhiteSpace(command.NationalCode) &&
x.id != employerId))
{
return operation.Failed(" کد ملی وارد شده تکراری است");
}
string initial = "1300/10/11";
var dateOfBirth = command.DateOfBirth?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime();
var dateOfIssue = command.DateOfIssue?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime();
var gender = command.Gender switch
{
Gender.Male => "مرد",
Gender.Female => "زن",
Gender.None => null,
_ => throw new BadRequestException("جنسیت وارد شده نامعتبر است")
};
employer.Edit(command.FName, command.LName, employer.ContractingPartyId,
gender, command.NationalCode, command.IdNumber, "ایرانی", command.FatherName,
dateOfBirth, dateOfIssue, command.PlaceOfIssue, command.PhoneNumber, command.Telephone,
command.GovernmentSystemInfo.MclUsername, command.GovernmentSystemInfo.MclPassword,
command.GovernmentSystemInfo.EServiceUsername, command.GovernmentSystemInfo.EServicePassword,
command.GovernmentSystemInfo.TaxUsername, command.GovernmentSystemInfo.TaxPassword,
command.GovernmentSystemInfo.SanaUsername, command.GovernmentSystemInfo.SanaPassword, null);
await _EmployerRepository.SaveChangesAsync();
return operation.Succcedded();
}
private async Task<OperationResult> EditLegalEmployerRegistration(
CreateLegalEmployerWorkflowRegistration command, long employerId)
{
var operation = new OperationResult();
var legalEmployer = _EmployerRepository.Get(employerId);
if (legalEmployer == null)
return operation.Failed("رکورد مورد نظر یافت نشد");
if (_EmployerRepository.Exists(x =>
x.LName == command.CompanyName && x.NationalId == command.NationalId &&
!string.IsNullOrWhiteSpace(command.NationalId) && x.id != employerId))
return operation.Failed("امکان ثبت رکورد تکراری وجود ندارد");
if (!string.IsNullOrEmpty(command.NationalId) && command.NationalId.Length != 11)
{
return operation.Failed(" شناسه ملی باید 11 رقم باشد");
}
if (!string.IsNullOrWhiteSpace(command.CeoNationalCode))
{
if (command.CeoNationalCode.NationalCodeValid() != "valid")
{
return operation.Failed("کد ملی وارد شده نا معتبر است");
}
}
var gender = command.Gender switch
{
Gender.Male => "مرد",
Gender.Female => "زن",
Gender.None => null,
_ => throw new BadRequestException("جنسیت وارد شده نامعتبر است")
};
string initial = "1300/10/11";
var dateOfBirth = command.CeoDateOfBirth?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime();
var dateOfIssue = command.CeoDateOfIssue?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime();
legalEmployer.EditLegal(command.CeoFName, command.CompanyName, legalEmployer.ContractingPartyId, gender,
command.CeoNationalCode, command.CeoIdNumber, "ایرانی", command.CeoFatherName, dateOfBirth,
dateOfIssue, command.CeoPlaceOfIssue, command.RegisterId, command.NationalId, command.CeoLName,
command.PhoneNumber, command.TelephoneNumber, command.GovernmentSystemInfo.MclUsername,
command.GovernmentSystemInfo.MclPassword, command.GovernmentSystemInfo.EServiceUsername,
command.GovernmentSystemInfo.EServicePassword,
command.GovernmentSystemInfo.TaxUsername, command.GovernmentSystemInfo.TaxPassword,
command.GovernmentSystemInfo.SanaUsername, command.GovernmentSystemInfo.SanaPassword, null);
await _EmployerRepository.SaveChangesAsync();
return operation.Succcedded();
}
#endregion
}

View File

@@ -64,6 +64,25 @@ namespace ServiceHost.Areas.Admin.Controllers
var result = await _employerApplication.AuthenticateEmployer(command.NationalCode, command.DateOfBirth, command.Mobile);
return result;
}
[HttpPut("edit-employer")]
public async Task<ActionResult<OperationResult>> EditEmployerForWorkshopDetails([FromBody]EditEmployerWorkflowRegistration command)
{
var result = await _employerApplication.EditWorkflowRegistration(command);
return result;
}
/// <summary>
/// حذف کارفرما از گردش کار ثبت نام
/// </summary>
/// <param name="employerId">شناسه کارفرما</param>
/// <param name="institutionWorkshopDetailsId">شناسه جزئیات کارگاه موسسه</param>
/// <returns></returns>
[HttpDelete("delete-employer/{employerId}/{institutionWorkshopDetailsId}")]
public async Task<ActionResult<OperationResult>> DeleteEmployerWorkflowRegistration(long employerId, long institutionWorkshopDetailsId)
{
var result = await _employerApplication.DeleteWorkflowRegistration(employerId, institutionWorkshopDetailsId);
return result;
}
}
public class AuthenticateEmployerWorkflowRequest