diff --git a/CompanyManagment.App.Contracts/Employer/IEmployerApplication.cs b/CompanyManagment.App.Contracts/Employer/IEmployerApplication.cs index 18b6db22..df65c7d3 100644 --- a/CompanyManagment.App.Contracts/Employer/IEmployerApplication.cs +++ b/CompanyManagment.App.Contracts/Employer/IEmployerApplication.cs @@ -129,7 +129,22 @@ public interface IEmployerApplication #endregion Task CreateWorkflowRegistration(CreateEmployerWorkflowRegistration command); - Task> AuthenticateEmployer(string nationalCode, string dateOfBirth, string mobile); + /// + /// ویرایش کارفرما در گردش کار ثبت نام + /// + /// + /// + Task EditWorkflowRegistration(EditEmployerWorkflowRegistration command); + + /// + /// حذف کارفرما از گردش کار ثبت نام + /// + /// شناسه کارفرما + /// شناسه جزئیات کارگاه موسسه + /// + Task DeleteWorkflowRegistration(long employerId, long institutionWorkshopDetailsId); + + Task> AuthenticateEmployer(string nationalCode, string dateOfBirth, string mobile); } public class AuthenticateUserViewModel @@ -384,4 +399,15 @@ public class CreateRealEmployerWorkflowRegistration /// شماره تلفن /// public string Telephone { get; set; } -} \ No newline at end of file +} + +/// +/// کلاس ویرایش کارفرما در گردش کار - شامل اطلاعات کارفرمای حقیقی و حقوقی +/// +public class EditEmployerWorkflowRegistration : CreateEmployerWorkflowRegistration +{ + /// + /// شناسه کارفرما + /// + public long EmployerId { get; set; } +} diff --git a/CompanyManagment.Application/EmployerApplication.cs b/CompanyManagment.Application/EmployerApplication.cs index 832e4538..16aba980 100644 --- a/CompanyManagment.Application/EmployerApplication.cs +++ b/CompanyManagment.Application/EmployerApplication.cs @@ -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> GetEmployerList(GetEmployerSearchModel searchModel) @@ -1320,6 +1331,66 @@ public class EmployerApplication : IEmployerApplication return operation.Succcedded(); } + public async Task 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(); + } + + /// + /// حذف کارفرما از گردش کار ثبت نام + /// + /// شناسه کارفرما + /// شناسه جزئیات کارگاه موسسه + /// + public async Task 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> AuthenticateEmployer(string nationalCode, string dateOfBirth, string mobile) @@ -1491,5 +1562,107 @@ public class EmployerApplication : IEmployerApplication return opration.Succcedded(employerData); } + private async Task 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 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 } \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Controllers/RegistrationWorkflowController.cs b/ServiceHost/Areas/Admin/Controllers/RegistrationWorkflowController.cs index 3f3d36a4..f6bdfe49 100644 --- a/ServiceHost/Areas/Admin/Controllers/RegistrationWorkflowController.cs +++ b/ServiceHost/Areas/Admin/Controllers/RegistrationWorkflowController.cs @@ -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> EditEmployerForWorkshopDetails([FromBody]EditEmployerWorkflowRegistration command) + { + var result = await _employerApplication.EditWorkflowRegistration(command); + return result; + } + + /// + /// حذف کارفرما از گردش کار ثبت نام + /// + /// شناسه کارفرما + /// شناسه جزئیات کارگاه موسسه + /// + [HttpDelete("delete-employer/{employerId}/{institutionWorkshopDetailsId}")] + public async Task> DeleteEmployerWorkflowRegistration(long employerId, long institutionWorkshopDetailsId) + { + var result = await _employerApplication.DeleteWorkflowRegistration(employerId, institutionWorkshopDetailsId); + return result; + } } public class AuthenticateEmployerWorkflowRequest