From d27b8484a25884b7d56d38f1697a096a0f890fd1 Mon Sep 17 00:00:00 2001 From: mahan Date: Mon, 23 Jun 2025 17:07:15 +0330 Subject: [PATCH] add entire teamwork api to original --- 0_Framework/0_Framework.csproj | 2 + 0_Framework/Application/Enums/Gender.cs | 8 - .../Handler/CustomExceptionHandler.cs | 76 +++++ .../Exceptions/UnAuthorizeException.cs | 10 + .../EmployeeAgg/IEmployeeRepository.cs | 7 +- .../IRepresentativeRepository.cs | 7 + .../empolyerAgg/IEmployerRepository.cs | 11 + .../CompanyManagment.App.Contracts.csproj | 27 +- .../Employee/GetEmployeeListSearchModel.cs | 38 +++ .../Employee/GetEmployeeListViewModel.cs | 44 +++ .../Employee/IEmployeeApplication.cs | 19 +- .../Employer/CreateLegalEmployer.cs | 84 +++++ .../Employer/CreateRealEmployer.cs | 80 +++++ .../Employer/EditLegalEmployer.cs | 9 + .../Employer/EditRealEmployer.cs | 12 + .../Employer/GetEmployerListViewModel.cs | 50 +++ .../Employer/GetEmployerSearchModel.cs | 44 +++ .../GetLegalEmployerDetailViewModel.cs | 120 ++++++++ .../GetRealEmployerDetailViewModel.cs | 107 +++++++ .../Employer/GovernmentSystemInfo.cs | 54 ++++ .../Employer/IEmployerApplication.cs | 73 ++++- .../CreateLegalRepresentative.cs | 46 +++ .../CreateRealRepresentative.cs | 54 ++++ .../Representative/EditLegalRepresentative.cs | 6 + .../Representative/EditRealRepresentative.cs | 6 + .../GetSelectListRepresentativeViewModel.cs | 17 ++ .../IRepresentativeApplication.cs | 21 +- .../RepresentativeGetListSearchModel.cs | 41 +++ .../RepresentativeGetListViewModel.cs | 29 ++ .../EmployeeAplication.cs | 16 +- .../EmployerApplication.cs | 262 +++++++++++++++- .../RepresentativeApplication.cs | 289 +++++++++++++++++- .../Repository/EmployeeRepository .cs | 107 ++++++- .../Repository/EmployerRepository.cs | 210 +++++++++++++ .../Repository/RepresentativeRepository.cs | 82 ++++- .../AdminMonthlyOverviewController.cs | 67 ++++ .../Admin/Controllers/EmployeesController.cs | 40 +++ .../Admin/Controllers/EmployerController.cs | 123 ++++++++ .../Controllers/RepresentativeController.cs | 151 +++++++++ .../Admin/Controllers/WorkshopController.cs | 28 ++ ServiceHost/Program.cs | 119 +++++++- ServiceHost/ServiceHost.csproj | 6 +- 42 files changed, 2566 insertions(+), 36 deletions(-) delete mode 100644 0_Framework/Application/Enums/Gender.cs create mode 100644 0_Framework/Exceptions/Handler/CustomExceptionHandler.cs create mode 100644 0_Framework/Exceptions/UnAuthorizeException.cs create mode 100644 CompanyManagment.App.Contracts/Employee/GetEmployeeListSearchModel.cs create mode 100644 CompanyManagment.App.Contracts/Employee/GetEmployeeListViewModel.cs create mode 100644 CompanyManagment.App.Contracts/Employer/CreateLegalEmployer.cs create mode 100644 CompanyManagment.App.Contracts/Employer/CreateRealEmployer.cs create mode 100644 CompanyManagment.App.Contracts/Employer/EditLegalEmployer.cs create mode 100644 CompanyManagment.App.Contracts/Employer/EditRealEmployer.cs create mode 100644 CompanyManagment.App.Contracts/Employer/GetEmployerListViewModel.cs create mode 100644 CompanyManagment.App.Contracts/Employer/GetEmployerSearchModel.cs create mode 100644 CompanyManagment.App.Contracts/Employer/GetLegalEmployerDetailViewModel.cs create mode 100644 CompanyManagment.App.Contracts/Employer/GetRealEmployerDetailViewModel.cs create mode 100644 CompanyManagment.App.Contracts/Employer/GovernmentSystemInfo.cs create mode 100644 CompanyManagment.App.Contracts/Representative/CreateLegalRepresentative.cs create mode 100644 CompanyManagment.App.Contracts/Representative/CreateRealRepresentative.cs create mode 100644 CompanyManagment.App.Contracts/Representative/EditLegalRepresentative.cs create mode 100644 CompanyManagment.App.Contracts/Representative/EditRealRepresentative.cs create mode 100644 CompanyManagment.App.Contracts/Representative/GetSelectListRepresentativeViewModel.cs create mode 100644 CompanyManagment.App.Contracts/Representative/RepresentativeGetListSearchModel.cs create mode 100644 CompanyManagment.App.Contracts/Representative/RepresentativeGetListViewModel.cs create mode 100644 ServiceHost/Areas/Admin/Controllers/AdminMonthlyOverviewController.cs create mode 100644 ServiceHost/Areas/Admin/Controllers/EmployeesController.cs create mode 100644 ServiceHost/Areas/Admin/Controllers/EmployerController.cs create mode 100644 ServiceHost/Areas/Admin/Controllers/RepresentativeController.cs create mode 100644 ServiceHost/Areas/Admin/Controllers/WorkshopController.cs diff --git a/0_Framework/0_Framework.csproj b/0_Framework/0_Framework.csproj index 04624e92..1de86aff 100644 --- a/0_Framework/0_Framework.csproj +++ b/0_Framework/0_Framework.csproj @@ -15,6 +15,8 @@ + + diff --git a/0_Framework/Application/Enums/Gender.cs b/0_Framework/Application/Enums/Gender.cs deleted file mode 100644 index 1b4077ca..00000000 --- a/0_Framework/Application/Enums/Gender.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace _0_Framework.Application.Enums; - -public enum Gender -{ - None, - Male, - Female -} \ No newline at end of file diff --git a/0_Framework/Exceptions/Handler/CustomExceptionHandler.cs b/0_Framework/Exceptions/Handler/CustomExceptionHandler.cs new file mode 100644 index 00000000..860aa62b --- /dev/null +++ b/0_Framework/Exceptions/Handler/CustomExceptionHandler.cs @@ -0,0 +1,76 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Diagnostics; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + + +namespace _0_Framework.Exceptions.Handler; + +public class CustomExceptionHandler : IExceptionHandler +{ + private readonly ILogger _logger; + + public CustomExceptionHandler(ILogger logger) + { + _logger = logger; + } + + public async ValueTask TryHandleAsync(HttpContext context, Exception exception, CancellationToken cancellationToken) + { + _logger.LogError( + "Error Message: {exceptionMessage}, Time of occurrence {time}", + exception.Message, DateTime.UtcNow); + + (string Detail, string Title, int StatusCode) details = exception switch + { + InternalServerException => + ( + exception.Message, + exception.GetType().Name, + context.Response.StatusCode = StatusCodes.Status500InternalServerError + ), + BadRequestException => + ( + exception.Message, + exception.GetType().Name, + context.Response.StatusCode = StatusCodes.Status400BadRequest + ), + NotFoundException => + ( + exception.Message, + exception.GetType().Name, + context.Response.StatusCode = StatusCodes.Status404NotFound + ), + UnAuthorizeException => + ( + exception.Message, + exception.GetType().Name, + context.Response.StatusCode = StatusCodes.Status401Unauthorized + ), + _ => + ( + exception.Message, + exception.GetType().Name, + context.Response.StatusCode = StatusCodes.Status500InternalServerError + ) + }; + + var problemDetails = new ProblemDetails + { + Title = details.Title, + Detail = details.Detail, + Status = details.StatusCode, + Instance = context.Request.Path + }; + + problemDetails.Extensions.Add("traceId", context.TraceIdentifier); + + + await context.Response.WriteAsJsonAsync(problemDetails, cancellationToken: cancellationToken); + + return true; + } +} \ No newline at end of file diff --git a/0_Framework/Exceptions/UnAuthorizeException.cs b/0_Framework/Exceptions/UnAuthorizeException.cs new file mode 100644 index 00000000..83edb8f9 --- /dev/null +++ b/0_Framework/Exceptions/UnAuthorizeException.cs @@ -0,0 +1,10 @@ +using System; + +namespace _0_Framework.Exceptions; + +public class UnAuthorizeException:Exception +{ + public UnAuthorizeException(string message) : base(message) + { + } +} \ No newline at end of file diff --git a/Company.Domain/EmployeeAgg/IEmployeeRepository.cs b/Company.Domain/EmployeeAgg/IEmployeeRepository.cs index ae689fb6..fa4f6eb3 100644 --- a/Company.Domain/EmployeeAgg/IEmployeeRepository.cs +++ b/Company.Domain/EmployeeAgg/IEmployeeRepository.cs @@ -71,7 +71,12 @@ public interface IEmployeeRepository : IRepository Task GetEmployeeEditInEmployeeDocumentWorkFlow(long employeeId, long workshopId); - #endregion + #endregion + + #region Api + Task> GetSelectList(string searchText); + Task> GetList(GetEmployeeListSearchModel searchModel); + #endregion } \ No newline at end of file diff --git a/Company.Domain/RepresentativeAgg/IRepresentativeRepository.cs b/Company.Domain/RepresentativeAgg/IRepresentativeRepository.cs index 784600be..e25364ad 100644 --- a/Company.Domain/RepresentativeAgg/IRepresentativeRepository.cs +++ b/Company.Domain/RepresentativeAgg/IRepresentativeRepository.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Threading.Tasks; using _0_Framework.Application; using _0_Framework.Domain; using CompanyManagment.App.Contracts.PersonalContractingParty; @@ -20,4 +21,10 @@ public interface IRepresentativeRepository : IRepository #endregion + #region Api + Task> GetList(RepresentativeGetListSearchModel searchModel); + bool HasAnyContractingParty(long id); + Task> GetSelectList(); + #endregion + } \ No newline at end of file diff --git a/Company.Domain/empolyerAgg/IEmployerRepository.cs b/Company.Domain/empolyerAgg/IEmployerRepository.cs index 1c8dc4e7..9b64f27a 100644 --- a/Company.Domain/empolyerAgg/IEmployerRepository.cs +++ b/Company.Domain/empolyerAgg/IEmployerRepository.cs @@ -56,6 +56,17 @@ public interface IEmployerRepository : IRepository #endregion + #region Api + Task> GetEmployerList(GetEmployerSearchModel searchModel); + + Task GetLegalEmployerDetail(long id); + Task GetRealEmployerDetail(long id); + //Task> GetSelectList(string search); + Task> DeactivateWithSubordinates(long id); + + + #endregion + } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/CompanyManagment.App.Contracts.csproj b/CompanyManagment.App.Contracts/CompanyManagment.App.Contracts.csproj index 2759a76d..affffa78 100644 --- a/CompanyManagment.App.Contracts/CompanyManagment.App.Contracts.csproj +++ b/CompanyManagment.App.Contracts/CompanyManagment.App.Contracts.csproj @@ -1,17 +1,22 @@ - - net8.0 - + + net8.0 + true + - - - + + + - - - - - + + + + + + + + + diff --git a/CompanyManagment.App.Contracts/Employee/GetEmployeeListSearchModel.cs b/CompanyManagment.App.Contracts/Employee/GetEmployeeListSearchModel.cs new file mode 100644 index 00000000..af2d923e --- /dev/null +++ b/CompanyManagment.App.Contracts/Employee/GetEmployeeListSearchModel.cs @@ -0,0 +1,38 @@ +using _0_Framework.Application.Enums; + +namespace CompanyManagment.App.Contracts.Employee; + +/// +/// مدل جستجو در لیست پرسنل در ادمین +/// +public class GetEmployeeListSearchModel +{ + /// + /// آیدی کارفرما + /// + public long EmployerId { get; set; } + /// + /// آیدی کارگاه + /// + public long WorkshopId { get; set; } + /// + /// آیدی پرسنل + /// + public long EmployeeId { get; set; } + /// + /// کدملی + /// + public string NationalCode { get; set; } + /// + /// شماره بیمه + /// + public string InsuranceCode { get; set; } + /// + /// وضعیت پرسنل + /// + public ActivationStatus EmployeeStatus { get; set; } + /// + /// ایندکس جستجو + /// + public int PageIndex { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Employee/GetEmployeeListViewModel.cs b/CompanyManagment.App.Contracts/Employee/GetEmployeeListViewModel.cs new file mode 100644 index 00000000..c5fde22e --- /dev/null +++ b/CompanyManagment.App.Contracts/Employee/GetEmployeeListViewModel.cs @@ -0,0 +1,44 @@ +using _0_Framework.Application; +using _0_Framework.Application.Enums; + +namespace CompanyManagment.App.Contracts.Employee; + +/// +/// ویو مدل لیست پرسنل ادمین +/// +public class GetEmployeeListViewModel +{ + /// + /// آیدی پرسنل + /// + public long Id { get; set; } + /// + /// نام و نام خانوادگی پرسنل + /// + public string EmployeeFullName { get; set; } + /// + /// کدملی + /// + public string NationalCode { get; set; } + + /// + /// تعداد فرزندان + /// + public string ChildrenCount { get; set; } + /// + /// جنسیت + /// + public Gender Gender { get; set; } + /// + /// تاریخ تولد + /// + public string BirthDate { get; set; } + /// + /// شماره بیمه + /// + public string InsuranceCode { get; set; } + /// + /// وضعیت پرسنل + /// + public ActivationStatus EmployeeStatus { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Employee/IEmployeeApplication.cs b/CompanyManagment.App.Contracts/Employee/IEmployeeApplication.cs index ec216d42..2624b605 100644 --- a/CompanyManagment.App.Contracts/Employee/IEmployeeApplication.cs +++ b/CompanyManagment.App.Contracts/Employee/IEmployeeApplication.cs @@ -77,6 +77,23 @@ public interface IEmployeeApplication Task> GetEmployeeDataFromApi(string nationalCode, string birthDate); - #endregion + #endregion + + #region Api + + /// + /// لیست پرسنل برای جستجو + /// + /// + /// + Task> GetSelectList(string searchText); + + /// + /// لیست کل پرسنل + /// + /// + Task> GetList(GetEmployeeListSearchModel searchModel); + + #endregion } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Employer/CreateLegalEmployer.cs b/CompanyManagment.App.Contracts/Employer/CreateLegalEmployer.cs new file mode 100644 index 00000000..a0224f7b --- /dev/null +++ b/CompanyManagment.App.Contracts/Employer/CreateLegalEmployer.cs @@ -0,0 +1,84 @@ +using System.ComponentModel.DataAnnotations; +using _0_Framework.Application; +using _0_Framework.Application.Enums; + +namespace CompanyManagment.App.Contracts.Employer; + +/// +/// ایجاد کارفرمای حقیقی +/// +public class CreateLegalEmployer +{ + /// + /// آیدی طرف حساب + /// + [Required] + public long ContractingPartyId { get; set; } + + /// + /// نام شرکت + /// + public string CompanyName { get; set; } + + /// + /// شناسه ملی + /// + public string NationalId { get; set; } + + /// + /// شماره ثبت + /// + public string RegisterId { get; set; } + + /// + /// شماره تلفن همراه + /// + public string PhoneNumber { get; set; } + + /// + /// شماره تلفن ثابت + /// + public string TelephoneNumber { get; set; } + + /// + /// نام مدیر عامل + /// + public string EmployerFName { get; set; } + /// + /// نام خانوادگی مدیر عامل + /// + public string EmployerLName { get; set; } + /// + /// جنسیت مدیر عامل + /// + public Gender EmployerGender { get; set; } + /// + /// کد ملی مدیر عامل + /// + public string EmployerNationalCode { get; set; } + /// + /// شماره شناسنامه مدیر عامل + /// + public string EmployerIdNumber { get; set; } + /// + /// نام پدر مدیر عامل + /// + public string EmployerFatherName { get; set; } + /// + /// تاریخ تولد مدیر عامل + /// + public string EmployerDateOfBirth { get; set; } + /// + /// تاریخ صدور شناسنامه مدیر عامل + /// + public string EmployerDateOfIssue { get; set; } + /// + /// محل صدور شناسنامه مدیر عامل + /// + public string EmployerPlaceOfIssue { get; set; } + + /// + /// اطلاعات سامانه ای + /// + public GovernmentSystemInfo GovernmentSystemInfo { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Employer/CreateRealEmployer.cs b/CompanyManagment.App.Contracts/Employer/CreateRealEmployer.cs new file mode 100644 index 00000000..998e6d75 --- /dev/null +++ b/CompanyManagment.App.Contracts/Employer/CreateRealEmployer.cs @@ -0,0 +1,80 @@ +using System.ComponentModel.DataAnnotations; +using _0_Framework.Application; +using _0_Framework.Application.Enums; + +namespace CompanyManagment.App.Contracts.Employer; + +/// +/// ایجاد کارفرما حقیقی +/// +public class CreateRealEmployer +{ + /// + /// آیدی طرف حساب + /// + [Required] + public long ContractingPartyId { get; set; } + + /// + /// جنسیت + /// + [Required] + public Gender Gender { get; set; } + + /// + /// نام + /// + [Required] + public string FName { get; set; } + + /// + ///نام خانوادگی + /// + [Required] + public string LName { get; set; } + + /// + /// کد ملی + /// + public string NationalCode { get; set; } + + /// + /// شماره شناسنامه + /// + public string IdNumber { get; set; } + + /// + /// شماره تلفن همراه + /// + public string PhoneNumber { get; set; } + + /// + /// شماره تلفن ثابت + /// + public string Telephone { get; set; } + + /// + /// تاریخ صدور شناسنامه + /// + public string DateOfIssue { get; set; } + + /// + /// محل صدور شناسنامه + /// + public string PlaceOfIssue { get; set; } + + /// + /// تاریخ تولد + /// + public string DateOfBirth { get; set; } + + /// + /// نام پدر + /// + public string FatherName { get; set; } + + /// + /// اطلاعات سامانه ای + /// + public GovernmentSystemInfo GovernmentSystemInfo { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Employer/EditLegalEmployer.cs b/CompanyManagment.App.Contracts/Employer/EditLegalEmployer.cs new file mode 100644 index 00000000..06d671d8 --- /dev/null +++ b/CompanyManagment.App.Contracts/Employer/EditLegalEmployer.cs @@ -0,0 +1,9 @@ +namespace CompanyManagment.App.Contracts.Employer; + +public class EditLegalEmployer: CreateLegalEmployer +{ + /// + /// آیدی کارفرما + /// + public long Id { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Employer/EditRealEmployer.cs b/CompanyManagment.App.Contracts/Employer/EditRealEmployer.cs new file mode 100644 index 00000000..bfe9c3e1 --- /dev/null +++ b/CompanyManagment.App.Contracts/Employer/EditRealEmployer.cs @@ -0,0 +1,12 @@ +namespace CompanyManagment.App.Contracts.Employer; + +/// +/// ویرایش کارفرما حقیقی +/// +public class EditRealEmployer:CreateRealEmployer +{ + /// + /// آیدی کارفرما + /// + public long Id { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Employer/GetEmployerListViewModel.cs b/CompanyManagment.App.Contracts/Employer/GetEmployerListViewModel.cs new file mode 100644 index 00000000..f75fc4b9 --- /dev/null +++ b/CompanyManagment.App.Contracts/Employer/GetEmployerListViewModel.cs @@ -0,0 +1,50 @@ +using System.Collections.Generic; +using _0_Framework.Application.Enums; + +namespace CompanyManagment.App.Contracts.Employer; + +/// +/// مدل برای گرفتن لیست کارفرما +/// +public class GetEmployerListViewModel +{ + /// + /// آیدی کارفرما + /// + public long Id { get; set; } + + /// + /// کدملی / شناسه ملی + /// + public string NationalCodeOrNationalId { get; set; } + + /// + /// نام کارفرما + /// + public string FullName { get; set; } + + /// + /// نام های کارگاه + /// + public ICollection WorkshopNames { get; set; } + + /// + /// دارای طرف حساب + /// + public bool HasContractingParty { get; set; } + + /// + /// طرف حساب بلاک شده یا نه + /// + public bool HasBlockContractingParty { get; set; } + + /// + /// نوع کارفرما + /// + public LegalType LegalType { get; set; } + + /// + /// وضعیت کارفرما + /// + public ActivationStatus EmployerStatus { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Employer/GetEmployerSearchModel.cs b/CompanyManagment.App.Contracts/Employer/GetEmployerSearchModel.cs new file mode 100644 index 00000000..738f6a25 --- /dev/null +++ b/CompanyManagment.App.Contracts/Employer/GetEmployerSearchModel.cs @@ -0,0 +1,44 @@ +using _0_Framework.Application.Enums; + +namespace CompanyManagment.App.Contracts.Employer; + +/// +/// مدل جستجوی لیست کارفرما +/// +public class GetEmployerSearchModel +{ + /// + /// نام شرکت / نام و نام خانوادگی + /// + public string FullNameOrCompanyName { get; set; } + + /// + /// کدملی/ شناسه ملی + /// + public string NationalCodeOrNationalId { get; set; } + + /// + /// شماره شناسنامه یا شماره ثبت + /// + public string IdNumberOrRegisterId { get; set; } + + /// + /// نام طرف حساب + /// + public string ContractingPartyName { get; set; } + + /// + /// وضعیت کارفرما + /// + public ActivationStatus EmployerStatus { get; set; } + + /// + /// نوع کارفرما + /// + public LegalType EmployerType { get; set; } + + /// + /// پیج ایندکس برای دسته بندی سی تایی + /// + public int PageIndex { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Employer/GetLegalEmployerDetailViewModel.cs b/CompanyManagment.App.Contracts/Employer/GetLegalEmployerDetailViewModel.cs new file mode 100644 index 00000000..9ffe398e --- /dev/null +++ b/CompanyManagment.App.Contracts/Employer/GetLegalEmployerDetailViewModel.cs @@ -0,0 +1,120 @@ +using _0_Framework.Application; +using _0_Framework.Application.Enums; + +namespace CompanyManagment.App.Contracts.Employer; + +/// +/// اطلاعات کارفرمای حقوقی +/// +public class GetLegalEmployerDetailViewModel +{ + /// + /// آیدی کارفرما + /// + public long Id { get; set; } + + /// + /// نام شرکت + /// + public string CompanyName { get; set; } + + /// + /// شناسه ملی + /// + public string NationalId { get; set; } + + /// + /// شماره ثبت + /// + public string RegisterId { get; set; } + + /// + /// شماره تلفن همراه + /// + public string PhoneNumber { get; set; } + + /// + /// شماره تلفن ثابت + /// + public string TelephoneNumber { get; set; } + + /// + /// کد کارفرما + /// + public string EmployerNo { get; set; } + + /// + /// نام کارفرما + /// + public string ContractingPartyName { get; set; } + + /// + /// نام کارفرما + /// + public long ContractingPartyId { get; set; } + + /// + /// نام و خانوادگی مدیر عامل + /// + public string CeoFullName { get; set; } + + /// + /// نام و خانوادگی مدیر عامل + /// + public string CeoFName { get; set; } + + /// + /// نام و خانوادگی مدیر عامل + /// + public string CeoLName { get; set; } + + /// + /// جنسیت مدیر عامل + /// + public Gender Gender { get; set; } + + /// + /// جنیست + /// + public string GenderStr { get; set; } + + /// + /// ملیت + /// + public string Nationality { get; set; } + + /// + /// نام پدر + /// + public string FatherName { get; set; } + + /// + /// کد ملی + /// + public string NationalCode { get; set; } + + /// + /// شماره شناسنامه + /// + public string IdNumber { get; set; } + + /// + /// تاریخ تولد + /// + public string DateOfBirth { get; set; } + /// + /// تاریخ صدور شناسنامه + /// + public string DateOfIssue { get; set; } + + /// + /// محل صدور شناسنامه + /// + public string PlaceOfIssue { get; set; } + + /// + /// اطلاعات سامانه های دولتی + /// + public GovernmentSystemInfo GovernmentSystemInfo { get; set; } + +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Employer/GetRealEmployerDetailViewModel.cs b/CompanyManagment.App.Contracts/Employer/GetRealEmployerDetailViewModel.cs new file mode 100644 index 00000000..9ace3ab6 --- /dev/null +++ b/CompanyManagment.App.Contracts/Employer/GetRealEmployerDetailViewModel.cs @@ -0,0 +1,107 @@ +using _0_Framework.Application; +using _0_Framework.Application.Enums; + +namespace CompanyManagment.App.Contracts.Employer; + +/// +/// اطلاعات کارفرمای حقوقی +/// +public class GetRealEmployerDetailViewModel +{ + /// + /// آیدی کارفرما + /// + public long Id { get; set; } + + /// + /// نام و نام خانوادگی + /// + public string FullName { get; set; } + + /// + /// نام + /// + public string FName{ get; set; } + + /// + /// نام خانوادگی + /// + public string LName { get; set; } + + /// + /// کدملی + /// + public string NationalCode { get; set; } + + /// + /// جنسیت فارسی + /// + public string GenderStr { get; set; } + + /// + /// جنسیت + /// + public Gender Gender { get; set; } + + /// + /// ملیت + /// + public string Nationality { get; set; } + + /// + /// شماره تلفن همراه + /// + public string PhoneNumber { get; set; } + + /// + /// نام پدر + /// + public string FatherName { get; set; } + + /// + /// شماره شناسنامه + /// + public string IdNumber { get; set; } + + /// + /// تاریخ تولد + /// + public string DateOfBirth { get; set; } + + /// + /// نام طرف حساب + /// + public string ContractingPartyName { get; set; } + + + /// + /// آیدی طرف حساب + /// + public long ContractingPartyId { get; set; } + + /// + /// کد کارفرما + /// + public string EmployerNo { get; set; } + + + /// + /// شماره تلفن ثابت + /// + public string TelephoneNumber { get; set; } + + /// + /// تاریخ صدور شناسنامه + /// + public string DateOfIssue { get; set; } + + /// + /// محل صدور شناسنامه + /// + public string PlaceOfIssue { get; set; } + + /// + /// اطلاعات سامانه های دولتی + /// + public GovernmentSystemInfo GovernmentSystemInfo { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Employer/GovernmentSystemInfo.cs b/CompanyManagment.App.Contracts/Employer/GovernmentSystemInfo.cs new file mode 100644 index 00000000..611ccb16 --- /dev/null +++ b/CompanyManagment.App.Contracts/Employer/GovernmentSystemInfo.cs @@ -0,0 +1,54 @@ +using System; + +namespace CompanyManagment.App.Contracts.Employer; + +/// +/// اطلاعات سامانه های دولتی +/// +public class GovernmentSystemInfo +{ + #region MCL + /// + /// نام کاربری اداره کار + /// + public string MclUsername { get; set; } + /// + /// رمز عبور اداره کار + /// + public string MclPassword { get; set; } + #endregion + + #region E-Service تامین اجتماعی + /// + /// نام کاربری سازمان تامین اجتماعی + /// + public string EServiceUsername { get; set; } + /// + /// رمز عبور سازمان تامین اجتماعی + /// + public string EServicePassword { get; set; } + #endregion + + #region Tax سامانه مالیاتی + /// + /// نام کاربری سامانه مالیاتی + /// + public string TaxUsername { get; set; } + /// + /// رمز عبور سامانه مالیاتی + /// + public string TaxPassword { get; set; } + #endregion + + #region Sana سامانه ثنا + /// + /// نام کاربری ثنا + /// + public string SanaUsername { get; set; } + /// + /// رمز عبور ثنا + /// + public string SanaPassword { get; set; } + #endregion + +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Employer/IEmployerApplication.cs b/CompanyManagment.App.Contracts/Employer/IEmployerApplication.cs index ec8582f1..86c5c41f 100644 --- a/CompanyManagment.App.Contracts/Employer/IEmployerApplication.cs +++ b/CompanyManagment.App.Contracts/Employer/IEmployerApplication.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using _0_Framework.Application; using CompanyManagment.App.Contracts.Checkout; +using CompanyManagment.App.Contracts.Employee; namespace CompanyManagment.App.Contracts.Employer; @@ -19,7 +20,7 @@ public interface IEmployerApplication OperationResult Active(long id); OperationResult DeActive(long id); - OperationResult Remove(long id); + OperationResult Remove_Old(long id); List GetEmployers(); List Search(EmployerSearchModel searchModel); @@ -36,7 +37,13 @@ public interface IEmployerApplication #region Mahan List GetEmployersHasWorkshop(); - Task> GetSelectList(string search); + + /// + /// لیست نام کارفرما ها برای جستجو + /// + /// + /// + Task> GetSelectList(string search); #endregion #region NewByHeydari @@ -53,6 +60,68 @@ public interface IEmployerApplication (string employerName, bool isLegal) InsuranceEmployerByWorkshopId(long workshopId); + + + #endregion + #region Api + /// + /// لیست کارفرما ها + /// + /// + Task> GetEmployerList(GetEmployerSearchModel searchModel); + + /// + /// جزئیات کارفرما حقوقی + /// + /// + /// + Task GetLegalEmployerDetail(long id); + + /// + /// جزئیات کارفرما حقیقی + /// + /// + /// + Task GetRealEmployerDetail(long id); + + /// + /// ایجاد کارفرمای حقیقی + /// + /// + /// + Task CreateReal(CreateRealEmployer command); + + /// + /// ایجاد کارفرمای حقوقی + /// + /// + /// + Task CreateLegal(CreateLegalEmployer command); + + /// + /// ویرایش کارفرمای حقیقی + /// + /// + /// + Task EditReal(EditRealEmployer command); + + + /// + /// ویرایش کارفرمای حقوقی + /// + /// + /// + Task EditLegal(EditLegalEmployer command); + + + + /// + /// حذف کارفرما - درصورت داشتن کارگاه کارفرما غیرفعال میشود + /// + /// + /// + public Task> Remove(long id); + #endregion } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Representative/CreateLegalRepresentative.cs b/CompanyManagment.App.Contracts/Representative/CreateLegalRepresentative.cs new file mode 100644 index 00000000..05bdfd2a --- /dev/null +++ b/CompanyManagment.App.Contracts/Representative/CreateLegalRepresentative.cs @@ -0,0 +1,46 @@ +using System.ComponentModel.DataAnnotations; + +namespace CompanyManagment.App.Contracts.Representative; + +public class CreateLegalRepresentative +{ + + /// + /// نام حقوقی + /// + [Required(ErrorMessage = "این مقدار نمی تواند خالی باشد")] + public string LegalName { get; set; } + + + /// + /// شناسه ثبت + /// + [RegularExpression("^[0-9]*$", ErrorMessage = "لطفا فقط عدد وارد کنید")] + public string RegisterId { get; set; } + + + /// + /// شناسه ملی + /// + [RegularExpression("[0-9]{11}", ErrorMessage = "لطفا فقط عدد 11 رقمی وارد کنید")] + public string NationalId { get; set; } + + + /// + /// شماره تلفن + /// + [DataType(DataType.PhoneNumber)] + [RegularExpression(@"^\(?([0-9]{4})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$", ErrorMessage = "لطفا شماره تلفن معتبر وارد کنید")] + public string Phone { get; set; } + + /// + /// شماره تلفن نماینده + /// + [RegularExpression("^[0-9]*$", ErrorMessage = "لطفا فقط عدد وارد کنید")] + public string AgentPhone { get; set; } + + /// + /// آدرس + /// + public string Address { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Representative/CreateRealRepresentative.cs b/CompanyManagment.App.Contracts/Representative/CreateRealRepresentative.cs new file mode 100644 index 00000000..35967dab --- /dev/null +++ b/CompanyManagment.App.Contracts/Representative/CreateRealRepresentative.cs @@ -0,0 +1,54 @@ +using System.ComponentModel.DataAnnotations; + +namespace CompanyManagment.App.Contracts.Representative; + +public class CreateRealRepresentative +{ + + + /// + /// نام کوچک + /// + [Required(ErrorMessage = "این مقدار نمی تواند خالی باشد")] + public string FName { get; set; } + + /// + /// نام خانوادگی + /// + [Required(ErrorMessage = "این مقدار نمی تواند خالی باشد")] + public string LName { get; set; } + + + /// + /// کد ملی + /// + [RegularExpression("^[0-9]*$", ErrorMessage = "لطفا فقط عدد وارد کنید")] + public string Nationalcode { get; set; } + + + /// + /// شماره شناسنامه + /// + [MaxLength(12)] + [MinLength(1)] + [RegularExpression("^[0-9]*$", ErrorMessage = "لطفا فقط عدد وارد کنید")] + public string IdNumber { get; set; } + + + /// + /// شماره تلفن + /// + [DataType(DataType.PhoneNumber)] + [RegularExpression(@"^\(?([0-9]{4})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$", ErrorMessage = "لطفا شماره تلفن معتبر وارد کنید")] + public string Phone { get; set; } + + + [RegularExpression("^[0-9]*$", ErrorMessage = "لطفا فقط عدد وارد کنید")] + public string AgentPhone { get; set; } + + /// + /// آدرس + /// + public string Address { get; set; } + +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Representative/EditLegalRepresentative.cs b/CompanyManagment.App.Contracts/Representative/EditLegalRepresentative.cs new file mode 100644 index 00000000..36e9198f --- /dev/null +++ b/CompanyManagment.App.Contracts/Representative/EditLegalRepresentative.cs @@ -0,0 +1,6 @@ +namespace CompanyManagment.App.Contracts.Representative; + +public class EditLegalRepresentative : CreateLegalRepresentative +{ + public long Id { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Representative/EditRealRepresentative.cs b/CompanyManagment.App.Contracts/Representative/EditRealRepresentative.cs new file mode 100644 index 00000000..0ee00e20 --- /dev/null +++ b/CompanyManagment.App.Contracts/Representative/EditRealRepresentative.cs @@ -0,0 +1,6 @@ +namespace CompanyManagment.App.Contracts.Representative; + +public class EditRealRepresentative : CreateRealRepresentative +{ + public long Id { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Representative/GetSelectListRepresentativeViewModel.cs b/CompanyManagment.App.Contracts/Representative/GetSelectListRepresentativeViewModel.cs new file mode 100644 index 00000000..5129d8d0 --- /dev/null +++ b/CompanyManagment.App.Contracts/Representative/GetSelectListRepresentativeViewModel.cs @@ -0,0 +1,17 @@ +namespace CompanyManagment.App.Contracts.Representative; + +/// +/// ویو مدل سلکت لیست برای معرف +/// +public class GetSelectListRepresentativeViewModel +{ + /// + /// آیدی + /// + public long Id { get; set; } + + /// + /// نام معرف + /// + public string Name { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Representative/IRepresentativeApplication.cs b/CompanyManagment.App.Contracts/Representative/IRepresentativeApplication.cs index 7c751c5d..ece54ff7 100644 --- a/CompanyManagment.App.Contracts/Representative/IRepresentativeApplication.cs +++ b/CompanyManagment.App.Contracts/Representative/IRepresentativeApplication.cs @@ -24,8 +24,27 @@ public interface IRepresentativeApplication OperationResult DeleteRepresentative(long id); OperationResult Active(long id); OperationResult DeActive(long id); - #endregion + #endregion + #region Api + + Task> GetList(RepresentativeGetListSearchModel searchModel); + + bool HasAnyContractingParty(long id); + + + OperationResult CreateReal(CreateRealRepresentative command); + OperationResult CreateLegal(CreateLegalRepresentative command); + OperationResult EditReal(EditRealRepresentative command); + OperationResult EditLegal(EditLegalRepresentative command); + + /// + /// لیست نام های معرف برای سلکت لیست + /// + /// + Task> GetSelectList(); + + #endregion } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Representative/RepresentativeGetListSearchModel.cs b/CompanyManagment.App.Contracts/Representative/RepresentativeGetListSearchModel.cs new file mode 100644 index 00000000..f3ce1dba --- /dev/null +++ b/CompanyManagment.App.Contracts/Representative/RepresentativeGetListSearchModel.cs @@ -0,0 +1,41 @@ +using _0_Framework.Application.Enums; + +namespace CompanyManagment.App.Contracts.Representative; + +public class RepresentativeGetListSearchModel +{ + + public int PageIndex { get; set; } + + /// + /// نام شرکت یا نام و نام خانوادگی + /// + public string CompanyNameOrFullName { get; set; } + + /// + /// شناسه ملی یا کدملی + /// + public string NationalCodeOrNationalId { get; set; } + + /// + /// شماره شناسنامه + /// + public string IdNumber { get; set; } + + /// + /// آیدی طرف حساب + /// + public long ContractingPartyId { get; set; } + + /// + /// نوع معرف + /// + public LegalType RepresentativeType { get; set; } + + + /// + /// وضعیت معرف + /// + public ActivationStatus RepresentativeStatus { get; set; } + +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Representative/RepresentativeGetListViewModel.cs b/CompanyManagment.App.Contracts/Representative/RepresentativeGetListViewModel.cs new file mode 100644 index 00000000..2fed51e0 --- /dev/null +++ b/CompanyManagment.App.Contracts/Representative/RepresentativeGetListViewModel.cs @@ -0,0 +1,29 @@ +using _0_Framework.Application.Enums; + +namespace CompanyManagment.App.Contracts.Representative; + +public class RepresentativeGetListViewModel +{ + /// + /// آیدی معرف + /// + public long Id { get; set; } + + /// + /// نام حقیقی یا نام حقوقی + /// + public string RealNameOrLegalName { get; set; } + + /// + /// کدملی یا شناسه ملی + /// + public string NationalIdOrNationalCode { get; set; } + + /// + /// آیا این معرف طرف حسابی دارد؟ + /// + public bool HasAnyContractingParty { get; set; } + + public ActivationStatus RepresentativeStatus { get; set; } + public LegalType RepresentativeType { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.Application/EmployeeAplication.cs b/CompanyManagment.Application/EmployeeAplication.cs index 5842c8eb..acf86fe6 100644 --- a/CompanyManagment.Application/EmployeeAplication.cs +++ b/CompanyManagment.Application/EmployeeAplication.cs @@ -1660,5 +1660,19 @@ public class EmployeeAplication : RepositoryBase, IEmployeeAppli } - #endregion + #endregion + + #region Api + + public async Task> GetSelectList(string searchText) + { + return await _EmployeeRepository.GetSelectList(searchText); + } + + public async Task> GetList(GetEmployeeListSearchModel searchModel) + { + return await _EmployeeRepository.GetList(searchModel); + } + + #endregion } \ No newline at end of file diff --git a/CompanyManagment.Application/EmployerApplication.cs b/CompanyManagment.Application/EmployerApplication.cs index 3c6eb318..6b937dcd 100644 --- a/CompanyManagment.Application/EmployerApplication.cs +++ b/CompanyManagment.Application/EmployerApplication.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using _0_Framework.Application; +using _0_Framework.Exceptions; using Company.Domain.empolyerAgg; using Company.Domain.WorkshopAgg; using CompanyManagment.App.Contracts.Checkout; @@ -239,7 +240,7 @@ public class EmployerApplication : IEmployerApplication return opration.Succcedded(); } - public OperationResult Remove(long id) + public OperationResult Remove_Old(long id) { var opration = new OperationResult(); @@ -894,10 +895,10 @@ public class EmployerApplication : IEmployerApplication return _EmployerRepository.GetEmployersHasWorkshop(); } - public async Task> GetSelectList(string search) - { - return await _EmployerRepository.GetSelectList(search); - } + //public async Task> GetSelectList(string search) + //{ + // return await _EmployerRepository.GetSelectList(search); + //} #endregion #region NewByHeydari @@ -957,4 +958,255 @@ public class EmployerApplication : IEmployerApplication } #endregion + + #region Api + public async Task> GetEmployerList(GetEmployerSearchModel searchModel) + { + return await _EmployerRepository.GetEmployerList(searchModel); + } + public async Task GetLegalEmployerDetail(long id) + { + var employer = await _EmployerRepository.GetLegalEmployerDetail(id); + if (employer == null) + { + throw new NotFoundException("کارفرمای مورد نطر یافت نشد"); + } + return employer; + } + + public async Task GetRealEmployerDetail(long id) + { + var employer = await _EmployerRepository.GetRealEmployerDetail(id); + if (employer == null) + { + throw new NotFoundException("کارفرمای مورد نطر یافت نشد"); + } + return employer; + } + + public async Task CreateReal(CreateRealEmployer command) + { + var opration = new OperationResult(); + if (_EmployerRepository.Exists(x => + (x.FName == command.FName && x.LName == command.LName) && x.Nationalcode == command.NationalCode && x.Nationalcode != null)) + return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد"); + + if (string.IsNullOrWhiteSpace(command.FName)) + return opration.Failed("لطفا نام را وارد کنید"); + + if (!string.IsNullOrWhiteSpace(command.NationalCode)) + { + if (command.NationalCode.NationalCodeValid() != "valid") + { + return opration.Failed("کدملی وارد شده نامعتبر است"); + } + if (_EmployerRepository.Exists(x => x.Nationalcode == command.NationalCode && !string.IsNullOrWhiteSpace(command.NationalCode))) + { + return opration.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("جنسیت وارد شده نامعتبر است") + }; + + var employerData = new Employer(command.FName, command.LName, command.ContractingPartyId, gender, + command.NationalCode, command.IdNumber, "ایرانی", command.FatherName, dateOfBirth, + dateOfIssue, command.PlaceOfIssue, "*", "*", "*", "حقیقی", command.PhoneNumber, + command.Telephone, "true", command.GovernmentSystemInfo.MclUsername, command.GovernmentSystemInfo.MclPassword, command.GovernmentSystemInfo.EServiceUsername, command.GovernmentSystemInfo.EServicePassword, + command.GovernmentSystemInfo.TaxUsername, command.GovernmentSystemInfo.TaxPassword, command.GovernmentSystemInfo.SanaUsername, command.GovernmentSystemInfo.SanaPassword); + + await _EmployerRepository.CreateAsync(employerData); + await _EmployerRepository.SaveChangesAsync(); + + return opration.Succcedded(); + } + + public async Task CreateLegal(CreateLegalEmployer command) + { + if (string.IsNullOrWhiteSpace(command.EmployerLName)) + command.EmployerLName = "#"; + var opration = new OperationResult(); + if (_EmployerRepository.Exists(x => + x.LName == command.CompanyName && x.NationalId == command.NationalId && x.EmployerLName == command.EmployerLName)) + return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد"); + + if (_EmployerRepository.Exists(x => x.NationalId == command.NationalId && !string.IsNullOrWhiteSpace(command.NationalId) && x.NationalId != null)) + { + return opration.Failed(" شناسه ملی وارد شده تکراری است"); + } + if (_EmployerRepository.Exists(x => x.LName == command.CompanyName)) + { + return opration.Failed("نام شرکت وارد شده تکراری است"); + } + if (_EmployerRepository.Exists(x => x.RegisterId == command.RegisterId && !string.IsNullOrWhiteSpace(command.RegisterId) && x.RegisterId != null)) + { + return opration.Failed(" شماره ثبت وارد شده تکراری است"); + } + + if (!string.IsNullOrEmpty(command.NationalId) && command.NationalId.Length != 11) + { + return opration.Failed(" شناسه ملی باید 11 رقم باشد"); + } + + if (!string.IsNullOrWhiteSpace(command.EmployerNationalCode)) + { + if (command.EmployerNationalCode.NationalCodeValid() != "valid") + { + return opration.Failed("کد ملی وارد شده نا معتبر است"); + } + } + + string initial = "1300/10/11"; + var dateOfBirth = command.EmployerDateOfBirth?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime(); + var dateOfIssue = command.EmployerDateOfIssue?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime(); + + var gender = command.EmployerGender switch + { + Gender.Male => "مرد", + Gender.Female => "زن", + Gender.None => null, + _ => throw new BadRequestException("جنسیت وارد شده نامعتبر است") + }; + + + var legalEmployerData = new Employer(command.EmployerFName, command.CompanyName, command.ContractingPartyId, gender, + command.EmployerNationalCode, command.EmployerIdNumber, "ایرانی", command.EmployerFatherName, dateOfBirth, + dateOfIssue, command.EmployerPlaceOfIssue, command.RegisterId, command.NationalId, command.EmployerLName, "حقوقی", command.PhoneNumber, + command.TelephoneNumber, "true", command.GovernmentSystemInfo.MclUsername, command.GovernmentSystemInfo.MclPassword, + command.GovernmentSystemInfo.EServiceUsername, command.GovernmentSystemInfo.EServicePassword, + command.GovernmentSystemInfo.TaxUsername, command.GovernmentSystemInfo.TaxPassword, command.GovernmentSystemInfo.SanaUsername, command.GovernmentSystemInfo.SanaPassword); + + await _EmployerRepository.CreateAsync(legalEmployerData); + await _EmployerRepository.SaveChangesAsync(); + + return opration.Succcedded(); + } + + public async Task EditReal(EditRealEmployer command) + { + var opration = new OperationResult(); + var employer = _EmployerRepository.Get(command.Id); + if (employer == null) + return opration.Failed("رکورد مورد نظر یافت نشد"); + + if (_EmployerRepository.Exists(x => + (x.FName == command.FName && x.LName == command.LName) && x.Nationalcode == command.NationalCode && x.id != command.Id)) + return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد"); + if (!string.IsNullOrWhiteSpace(command.NationalCode)) + { + if (command.NationalCode.NationalCodeValid() != "valid") + { + return opration.Failed("کد ملی وارد شده نا معتبر است"); + } + } + + if (_EmployerRepository.Exists(x => x.Nationalcode == command.NationalCode && !string.IsNullOrWhiteSpace(command.NationalCode) && x.id != command.Id)) + { + + return opration.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, command.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 opration.Succcedded(); + } + + public async Task EditLegal(EditLegalEmployer command) + { + var opration = new OperationResult(); + var legalEmployer = _EmployerRepository.Get(command.Id); + if (legalEmployer == null) + return opration.Failed("رکورد مورد نظر یافت نشد"); + + if (_EmployerRepository.Exists(x => + x.LName == command.CompanyName && x.NationalId == command.NationalId && !string.IsNullOrWhiteSpace(command.NationalId) && x.id != command.Id)) + return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد"); + + + if (!string.IsNullOrEmpty(command.NationalId) && command.NationalId.Length != 11) + { + return opration.Failed(" شناسه ملی باید 11 رقم باشد"); + } + + if (!string.IsNullOrWhiteSpace(command.EmployerNationalCode)) + { + if (command.EmployerNationalCode.NationalCodeValid() != "valid") + { + return opration.Failed("کد ملی وارد شده نا معتبر است"); + } + } + + var gender = command.EmployerGender switch + { + Gender.Male => "مرد", + Gender.Female => "زن", + Gender.None => null, + _ => throw new BadRequestException("جنسیت وارد شده نامعتبر است") + }; + + string initial = "1300/10/11"; + var dateOfBirth = command.EmployerDateOfBirth?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime(); + var dateOfIssue = command.EmployerDateOfIssue?.ToGeorgianDateTime() ?? initial.ToGeorgianDateTime(); + legalEmployer.EditLegal(command.EmployerFName, command.CompanyName, command.ContractingPartyId, gender, + command.EmployerNationalCode, command.EmployerIdNumber, "ایرانی", command.EmployerFatherName, dateOfBirth, + dateOfIssue, command.EmployerPlaceOfIssue, command.RegisterId, command.NationalId, command.EmployerLName, + command.PhoneNumber, command.TelephoneNumber, command.GovernmentSystemInfo.MclUsername, command.GovernmentSystemInfo.MclUsername, command.GovernmentSystemInfo.EServiceUsername, command.GovernmentSystemInfo.EServicePassword, + command.GovernmentSystemInfo.TaxUsername, command.GovernmentSystemInfo.TaxPassword, command.GovernmentSystemInfo.SanaUsername, command.GovernmentSystemInfo.SanaPassword, null); + + await _EmployerRepository.SaveChangesAsync(); + return opration.Succcedded(); + } + + public async Task> GetSelectList(string search) + { + return await _EmployerRepository.GetSelectList(search); + } + + async Task> IEmployerApplication.Remove(long id) + { + var employer = _EmployerRepository.Get(id); + if (employer == null) + throw new NotFoundException("دیتای مورد نظر یافت نشد"); + + var workshops = _workshopRepository.GetWorkshopsByEmployerId([id]); + + if (workshops.Any()) + { + return await _EmployerRepository.DeactivateWithSubordinates(id); + } + + _EmployerRepository.Remove(id); + + return new OperationResult().Succcedded("Deleted"); + + } + #endregion } \ No newline at end of file diff --git a/CompanyManagment.Application/RepresentativeApplication.cs b/CompanyManagment.Application/RepresentativeApplication.cs index 78541931..a8bd4f0b 100644 --- a/CompanyManagment.Application/RepresentativeApplication.cs +++ b/CompanyManagment.Application/RepresentativeApplication.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; using _0_Framework.Application; using Company.Domain.RepresentativeAgg; using CompanyManagment.App.Contracts.PersonalContractingParty; @@ -350,5 +352,290 @@ public class RepresentativeApplication : IRepresentativeApplication _representativeRepository.SaveChanges(); return opration.Succcedded(); } - #endregion + #endregion + + #region Api + public OperationResult CreateReal(CreateRealRepresentative command) + { + var nationalCode = string.Empty; + var op = new OperationResult(); + if (_representativeRepository.Exists(x => + x.LName == command.LName && x.Nationalcode == command.Nationalcode)) + return op.Failed("امکان ثبت رکورد تکراری وجود ندارد"); + if (_representativeRepository.Exists(x => x.LName == command.LName)) + { + + + return op.Failed("نام خانوادگی وارد شده تکراری است"); + + } + if (_representativeRepository.Exists(x => x.Nationalcode == command.Nationalcode)) + { + + + return op.Failed("کد ملی وارد شده تکراری است"); + } + + if (!string.IsNullOrWhiteSpace(command.Nationalcode)) + { + if (_representativeRepository.Exists(x => x.Nationalcode == command.Nationalcode)) + { + + + return op.Failed("کد ملی وارد شده تکراری است"); + } + try + { + + + char[] chArray = command.Nationalcode.ToCharArray(); + int[] numArray = new int[chArray.Length]; + var cunt = chArray.Length; + for (int i = 0; i < chArray.Length; i++) + { + numArray[i] = (int)char.GetNumericValue(chArray[i]); + } + + int num2 = numArray[9]; + switch (command.Nationalcode) + { + case "0000000000": + case "1111111111": + case "22222222222": + case "33333333333": + case "4444444444": + case "5555555555": + case "6666666666": + case "7777777777": + case "8888888888": + case "9999999999": + + + + + return op.Failed("کد ملی وارد شده صحیح نمی باشد"); + + + } + + int num3 = + ((((((((numArray[0] * 10) + (numArray[1] * 9)) + (numArray[2] * 8)) + (numArray[3] * 7)) + + (numArray[4] * 6)) + (numArray[5] * 5)) + (numArray[6] * 4)) + (numArray[7] * 3)) + + (numArray[8] * 2); + int num4 = num3 - ((num3 / 11) * 11); + if ((((num4 == 0) && (num2 == num4)) || ((num4 == 1) && (num2 == 1))) || + ((num4 > 1) && (num2 == Math.Abs((int)(num4 - 11)))) && cunt <= 10) + { + + + + + nationalCode = command.Nationalcode; + + + } + else + { + + + return op.Failed("کد ملی وارد شده نا معتبر است"); + } + } + catch (Exception) + { + + return op.Failed("لطفا کد ملی 10 رقمی وارد کنید"); + + } + + } + else + { + nationalCode = ""; + } + + var createReal = new Representative(command.FName, command.LName, "*", + nationalCode, command.IdNumber, "*", "*", + "false", command.Phone, command.AgentPhone, command.Address + ); + + + _representativeRepository.Create(createReal); + _representativeRepository.SaveChanges(); + + return op.Succcedded(); + + + + } + + public OperationResult CreateLegal(CreateLegalRepresentative command) + + { + var op = new OperationResult(); + if (_representativeRepository.Exists(x => + x.LegalName == command.LegalName && x.RegisterId == command.RegisterId)) + return op.Failed("امکان ثبت رکورد تکراری وجود ندارد"); + if (_representativeRepository.Exists(x => x.LegalName == command.LegalName)) + { + legalNameIsOk = false; + return op.Failed("نام شرکت وارد شده تکراری است"); + } + if (_representativeRepository.Exists(x => x.RegisterId == command.RegisterId)) + { + + return op.Failed("شماره ثبت وارد شده تکراری است"); + + } + if (_representativeRepository.Exists(x => x.NationalId == command.NationalId)) + { + + return op.Failed("شناسه ملی وارد شده تکراری است"); + } + var createLegal = new Representative("*", "*", + command.LegalName, "*", "*", command.RegisterId, command.NationalId, + "true", + command.Phone, command.AgentPhone, command.Address); + + + _representativeRepository.Create(createLegal); + _representativeRepository.SaveChanges(); + + return op.Succcedded(); + + + } + + public OperationResult EditReal(EditRealRepresentative command) + { + var nationalCode = string.Empty; + var opration = new OperationResult(); + var representativeRealEdit = _representativeRepository.Get(command.Id); + if (representativeRealEdit == null) + return opration.Failed("رکورد مورد نظر یافت نشد"); + + if (_representativeRepository.Exists(x => + x.LName == command.LName && x.FName == command.FName && x.id != command.Id)) + return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد"); + if (!string.IsNullOrWhiteSpace(command.Nationalcode)) + { + if (_representativeRepository.Exists(x => x.Nationalcode == command.Nationalcode && x.id != command.Id)) + { + + + return opration.Failed("کد ملی وارد شده تکراری است"); + } + try + { + + + char[] chArray = command.Nationalcode.ToCharArray(); + int[] numArray = new int[chArray.Length]; + var cunt = chArray.Length; + for (int i = 0; i < chArray.Length; i++) + { + numArray[i] = (int)char.GetNumericValue(chArray[i]); + } + + int num2 = numArray[9]; + switch (command.Nationalcode) + { + case "0000000000": + case "1111111111": + case "22222222222": + case "33333333333": + case "4444444444": + case "5555555555": + case "6666666666": + case "7777777777": + case "8888888888": + case "9999999999": + + + + + return opration.Failed("کد ملی وارد شده صحیح نمی باشد"); + + + } + + int num3 = + ((((((((numArray[0] * 10) + (numArray[1] * 9)) + (numArray[2] * 8)) + (numArray[3] * 7)) + + (numArray[4] * 6)) + (numArray[5] * 5)) + (numArray[6] * 4)) + (numArray[7] * 3)) + + (numArray[8] * 2); + int num4 = num3 - ((num3 / 11) * 11); + if ((((num4 == 0) && (num2 == num4)) || ((num4 == 1) && (num2 == 1))) || + ((num4 > 1) && (num2 == Math.Abs((int)(num4 - 11)))) && cunt <= 10) + { + + + + + nationalCode = command.Nationalcode; + + + } + else + { + + + return opration.Failed("کد ملی وارد شده نا معتبر است"); + } + } + catch (Exception) + { + + return opration.Failed("لطفا کد ملی 10 رقمی وارد کنید"); + + } + + } + else + { + nationalCode = ""; + } + + representativeRealEdit.EditReal(command.FName, command.LName, + nationalCode, command.IdNumber, + command.Phone, command.AgentPhone, command.Address); + + _representativeRepository.SaveChanges(); + return opration.Succcedded(); + + } + public OperationResult EditLegal(EditLegalRepresentative command) + { + var opration = new OperationResult(); + var representativeLegalEdit = _representativeRepository.Get(command.Id); + if (representativeLegalEdit == null) + return opration.Failed("رکورد مورد نظر یافت نشد"); + + if (_representativeRepository.Exists(x => + x.LegalName == command.LegalName && x.RegisterId == command.RegisterId && x.id != command.Id)) + return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد"); + + representativeLegalEdit.EditLegal(command.LegalName, command.RegisterId, + command.NationalId, + command.Phone, command.AgentPhone, command.Address); + + _representativeRepository.SaveChanges(); + return opration.Succcedded(); + } + + public async Task> GetSelectList() + { + return await _representativeRepository.GetSelectList(); + } + + public async Task> GetList(RepresentativeGetListSearchModel searchModel) + { + return (await _representativeRepository.GetList(searchModel)).ToList(); + } + + public bool HasAnyContractingParty(long id) + { + return _representativeRepository.HasAnyContractingParty(id); + } + + #endregion } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/EmployeeRepository .cs b/CompanyManagment.EFCore/Repository/EmployeeRepository .cs index 57a2c25c..91b75ed3 100644 --- a/CompanyManagment.EFCore/Repository/EmployeeRepository .cs +++ b/CompanyManagment.EFCore/Repository/EmployeeRepository .cs @@ -16,6 +16,8 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using CompanyManagment.App.Contracts.Employee.DTO; using CompanyManagment.App.Contracts.LeftWorkTemp; +using _0_Framework.Application.Enums; +using _0_Framework.Exceptions; namespace CompanyManagment.EFCore.Repository; @@ -944,5 +946,108 @@ public class EmployeeRepository : RepositoryBase, IEmployeeRepos }).ToList(); } - #endregion + #endregion + + #region Api + + public async Task> GetSelectList(string searchText) + { + var query = _context.Employees.AsQueryable(); + + if (!string.IsNullOrWhiteSpace(searchText)) + { + query = query.Where(x => (x.FName + " " + x.LName).Contains(searchText)); + } + + return await query.Take(100).Select(x => new EmployeeSelectListViewModel() + { + Id = x.id, + EmployeeFullName = x.FName + " " + x.LName + }).ToListAsync(); + + } + + public async Task> GetList(GetEmployeeListSearchModel searchModel) + { + var query = _context.Employees.Include(x => x.LeftWorks).Include(x => x.LeftWorkInsurances).AsQueryable(); + + if (!string.IsNullOrWhiteSpace(searchModel.NationalCode)) + { + query = query.Where(x => x.NationalCode.Contains(searchModel.NationalCode)); + } + + if (searchModel.EmployeeId > 0) + { + query = query.Where(x => x.id == searchModel.EmployeeId); + } + + if (searchModel.WorkshopId > 0) + { + query = query.Where(x => x.LeftWorks.Any(l => l.WorkshopId == searchModel.WorkshopId) || x.LeftWorkInsurances.Any(l => l.WorkshopId == searchModel.WorkshopId)); + } + + + #region employer + + if (searchModel.EmployerId > 0) + { + + var workshopIdsByEmployer = _context.WorkshopEmployers.Where(x => x.EmployerId == searchModel.EmployerId) + .Include(x => x.Workshop).Select(x => x.Workshop.id).AsQueryable(); + + query = query.Where(x => + x.LeftWorks.Any(l => workshopIdsByEmployer.Contains(l.WorkshopId)) || + x.LeftWorkInsurances.Any(l => workshopIdsByEmployer.Contains(l.WorkshopId))); + + } + #endregion + + if (!string.IsNullOrEmpty(searchModel.InsuranceCode)) + { + query = query.Where(x => x.InsuranceCode.Contains(searchModel.InsuranceCode)); + } + + if (searchModel.EmployeeStatus != ActivationStatus.None) + { + var status = searchModel.EmployeeStatus switch + { + ActivationStatus.Active => true, + ActivationStatus.DeActive => false, + _ => throw new BadRequestException("پارامتر جستجو نامعتبر است") + }; + query = query.Where(x => x.IsActiveString == status.ToString() || x.IsActive == status); + } + + var list = await query.Skip(searchModel.PageIndex).Take(30).ToListAsync(); + + var employeeIds = list.Select(x => x.id); + + var children = await _context.EmployeeChildrenSet.Where(x => employeeIds.Contains(x.EmployeeId)).ToListAsync(); + + var result = list.Select(x => new GetEmployeeListViewModel() + { + BirthDate = x.DateOfBirth.ToFarsi(), + ChildrenCount = children.Count(c => c.EmployeeId == x.id).ToString(), + EmployeeFullName = x.FullName, + EmployeeStatus = x.IsActive switch + { + true => ActivationStatus.Active, + false => ActivationStatus.DeActive + }, + Gender = x.Gender switch + { + "مرد" => Gender.Male, + "زن" => Gender.Female, + _ => Gender.None + }, + Id = x.id, + InsuranceCode = x.InsuranceCode, + NationalCode = x.NationalCode + }).ToList(); + + return result; + + } + + #endregion } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/EmployerRepository.cs b/CompanyManagment.EFCore/Repository/EmployerRepository.cs index 1344248d..934c6e00 100644 --- a/CompanyManagment.EFCore/Repository/EmployerRepository.cs +++ b/CompanyManagment.EFCore/Repository/EmployerRepository.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using _0_Framework.Application; +using _0_Framework.Application.Enums; using _0_Framework.InfraStructure; using Company.Domain.EmployerAccountAgg; using Company.Domain.empolyerAgg; @@ -786,4 +787,213 @@ public class EmployerRepository : RepositoryBase, IEmployerRepos } #endregion + + #region Api + public async Task> GetEmployerList(GetEmployerSearchModel searchModel) + { + var query = _context.Employers.Include(x => x.ContractingParty).Include(x => x.WorkshopEmployers).ThenInclude(x => x.Workshop).AsQueryable(); + + if (!string.IsNullOrWhiteSpace(searchModel.FullNameOrCompanyName)) + query = query.Where(x => x.FullName.Contains(searchModel.FullNameOrCompanyName)); + + + if (!string.IsNullOrWhiteSpace(searchModel.NationalCodeOrNationalId)) + query = query.Where(x => x.Nationalcode.Contains(searchModel.NationalCodeOrNationalId) || x.NationalId.Contains(searchModel.NationalCodeOrNationalId)); + + if (!string.IsNullOrWhiteSpace(searchModel.IdNumberOrRegisterId)) + query = query.Where(x => x.IdNumber.Contains(searchModel.IdNumberOrRegisterId) || x.RegisterId.Contains(searchModel.IdNumberOrRegisterId)); + + + if (searchModel.EmployerType != LegalType.None) + { + var type = searchModel.EmployerType switch + { + LegalType.Legal => "true", + LegalType.Real => "false", + _ => "", + }; + + query = query.Where(x => x.IsLegal == type); + } + + if (searchModel.EmployerStatus != ActivationStatus.None) + { + var status = searchModel.EmployerStatus switch + { + ActivationStatus.Active => true, + ActivationStatus.DeActive => false, + _ => false + }; + query = query.Where(x => x.IsActive == status); + } + + if (!string.IsNullOrEmpty(searchModel.ContractingPartyName)) + { + query = query.Where(x => + x.ContractingParty.IsLegal == "true" + ? (x.ContractingParty.LName).Contains(searchModel.ContractingPartyName) + : (x.ContractingParty.FName + " " + x.ContractingParty.LName).Contains(searchModel + .ContractingPartyName)); + } + + var employerList = await query.Select(x => new GetEmployerListViewModel() + { + Id = x.id, + FullName = x.FullName, + HasContractingParty = x.ContractingPartyId == 30428 && x.WorkshopEmployers.Any(), + HasBlockContractingParty = x.ContractingParty.IsBlock == "true", + NationalCodeOrNationalId = x.IsLegal == "true" ? x.NationalId : x.Nationalcode, + WorkshopNames = x.WorkshopEmployers.Select(w => w.Workshop.WorkshopFullName).ToList(), + LegalType = x.IsLegal == "حقیقی" ? LegalType.Real : LegalType.Legal, + EmployerStatus = x.IsActive ? ActivationStatus.Active : ActivationStatus.DeActive, + + }).Skip(searchModel.PageIndex).Take(30).ToListAsync(); + return employerList; + } + + public async Task GetLegalEmployerDetail(long id) + { + var employer = await _context.Employers.Where(x => x.IsLegal == "حقوقی").Include(x => x.ContractingParty).Select(x => + new GetLegalEmployerDetailViewModel() + { + Id = x.id, + CompanyName = x.LName, + ContractingPartyName = x.ContractingParty.FName + " " + x.ContractingParty.LName, + DateOfBirth = x.DateOfBirth.ToFarsi(), + DateOfIssue = x.DateOfIssue.ToFarsi(), + CeoFullName = x.FName + " " + x.EmployerLName, + EmployerNo = x.EmployerNo, + FatherName = x.FatherName, + GenderStr = x.Gender, + Gender = string.IsNullOrWhiteSpace(x.Gender) ? Gender.None : + x.Gender == "مرد" ? + Gender.Male : + Gender.Female, + NationalCode = x.Nationalcode, + IdNumber = x.IdNumber, + NationalId = x.NationalId, + Nationality = x.Nationality, + PhoneNumber = x.Phone, + PlaceOfIssue = x.PlaceOfIssue, + RegisterId = x.RegisterId, + TelephoneNumber = x.AgentPhone, + CeoFName = x.FName, + CeoLName = x.EmployerLName, + GovernmentSystemInfo = new GovernmentSystemInfo + { + EServicePassword = x.EservicePassword, + EServiceUsername = x.EservicePassword, + MclPassword = x.MclsPassword, + MclUsername = x.MclsUserName, + SanaUsername = x.SanaUserName, + SanaPassword = x.SanaPassword, + TaxUsername = x.TaxOfficeUserName, + TaxPassword = x.TaxOfficepassword + }, + ContractingPartyId = x.ContractingPartyId + }).FirstOrDefaultAsync(x => x.Id == id); + + return employer; + } + + public async Task GetRealEmployerDetail(long id) + { + var employer = await _context.Employers.Where(x => x.IsLegal == "حقیقی").Include(x => x.ContractingParty).Select(x => + new GetRealEmployerDetailViewModel() + { + Id = x.id, + ContractingPartyName = x.ContractingParty.FName + " " + x.ContractingParty.LName, + DateOfBirth = x.DateOfBirth.ToFarsi(), + DateOfIssue = x.DateOfIssue.ToFarsi(), + EmployerNo = x.EmployerNo, + FatherName = x.FatherName, + GenderStr = x.Gender, + Gender = string.IsNullOrWhiteSpace(x.Gender) ? Gender.None : + x.Gender == "مرد" ? + Gender.Male : + Gender.Female, + NationalCode = x.Nationalcode, + IdNumber = x.IdNumber, + Nationality = x.Nationality, + PhoneNumber = x.Phone, + PlaceOfIssue = x.PlaceOfIssue, + TelephoneNumber = x.AgentPhone, + FullName = x.FullName, + FName = x.FName, + LName = x.LName, + GovernmentSystemInfo = new GovernmentSystemInfo + { + EServicePassword = x.EservicePassword, + EServiceUsername = x.EservicePassword, + MclPassword = x.MclsPassword, + MclUsername = x.MclsUserName, + SanaUsername = x.SanaUserName, + SanaPassword = x.SanaPassword, + TaxUsername = x.TaxOfficeUserName, + TaxPassword = x.TaxOfficepassword + }, + ContractingPartyId = x.ContractingPartyId + }).FirstOrDefaultAsync(x => x.Id == id); + + return employer; + } + + + public async Task> DeactivateWithSubordinates(long id) + { + var op = new OperationResult(); + ; + using (var transaction = await _context.Database.BeginTransactionAsync()) + { + try + { + var employer = await _context.Employers + .Include(x => x.Contracts) + .Include(x => x.WorkshopEmployers) + .ThenInclude(x => x.Workshop) + .ThenInclude(x => x.Checkouts).FirstOrDefaultAsync(x => x.id == id); + if (employer == null) + { + return op.Failed("چنین آیتمی وجود ندارد"); + } + + + var workshops = employer.WorkshopEmployers.Select(x => x.Workshop).ToList(); + + var contracts = employer.Contracts.ToList(); + + var checkouts = workshops.SelectMany(x => x.Checkouts).ToList(); + + + employer.DeActive(); + + foreach (var workshop in workshops) + { + workshop.DeActive(workshop.ArchiveCode); + } + + foreach (var contract in contracts) + { + contract.DeActive(); + } + + foreach (var checkout in checkouts) + { + checkout.DeActive(); + } + + await _context.SaveChangesAsync(); + + await transaction.CommitAsync(); + return op.Succcedded("DeActivate"); + } + catch (Exception) + { + await transaction.RollbackAsync(); + return op.Failed("غیرفعال کردن کارفرما با خطا مواجه شد"); + } + } + } + + #endregion } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/RepresentativeRepository.cs b/CompanyManagment.EFCore/Repository/RepresentativeRepository.cs index f7c23ed1..8179f39d 100644 --- a/CompanyManagment.EFCore/Repository/RepresentativeRepository.cs +++ b/CompanyManagment.EFCore/Repository/RepresentativeRepository.cs @@ -1,10 +1,13 @@ using System; using System.Collections.Generic; using System.Linq; +using _0_Framework.Application.Enums; +using System.Threading.Tasks; using _0_Framework.InfraStructure; using Company.Domain.RepresentativeAgg; using CompanyManagment.App.Contracts.PersonalContractingParty; using CompanyManagment.App.Contracts.Representative; +using Microsoft.EntityFrameworkCore; namespace CompanyManagment.EFCore.Repository; @@ -213,5 +216,82 @@ public class RepresentativeRepository : RepositoryBase, IR } - #endregion + #endregion + + #region Api + public async Task> GetList(RepresentativeGetListSearchModel searchModel) + { + var query = _context.RepresentativeSet.Include(x => x.ContractingParties) + .Where(x => x.FullName != "-"); + + if (!string.IsNullOrWhiteSpace(searchModel.CompanyNameOrFullName)) + query = query.Where(x => x.FullName.Contains(searchModel.CompanyNameOrFullName)); + + if (!string.IsNullOrWhiteSpace(searchModel.NationalCodeOrNationalId)) + query = query.Where(x => x.Nationalcode.Contains(searchModel.NationalCodeOrNationalId) + || x.NationalId.Contains(searchModel.NationalCodeOrNationalId)); + + if (!string.IsNullOrWhiteSpace(searchModel.IdNumber)) + query = query.Where(x => x.IdNumber.Contains(searchModel.IdNumber)); + + + if (searchModel.ContractingPartyId > 0) + { + query = query.Where(x => x.ContractingParties.Any(c => c.id == searchModel.ContractingPartyId)); + } + + if (searchModel.RepresentativeType != LegalType.None) + { + string isLegal = searchModel.RepresentativeType switch + { + LegalType.Real => "false", + LegalType.Legal => "true", + _ => "" + }; + + query = query.Where(x => x.IsLegal == isLegal); + } + + if (searchModel.RepresentativeStatus != ActivationStatus.None) + { + string status = searchModel.RepresentativeStatus switch + { + ActivationStatus.Active => "true", + ActivationStatus.DeActive => "false", + _ => "" + }; + query = query.Where(x => x.IsActive == status); + } + + var result = await query.Skip(searchModel.PageIndex).Take(30) + .Select(x => new RepresentativeGetListViewModel() + { + Id = x.id, + NationalIdOrNationalCode = x.IsLegal == "true" ? x.NationalId : x.Nationalcode, + RealNameOrLegalName = x.FullName, + HasAnyContractingParty = x.ContractingParties.Any(), + RepresentativeStatus = x.IsActive == "false" ? ActivationStatus.DeActive : ActivationStatus.Active, + RepresentativeType = x.IsLegal == "true" ? LegalType.Legal : LegalType.Real, + }).ToListAsync(); + + return result; + + } + + public bool HasAnyContractingParty(long id) + { + return _context.RepresentativeSet.Where(x => x.id == id).Include(x => x.ContractingParties) + .Any(x => x.ContractingParties.Any()); + } + + public async Task> GetSelectList() + { + return await _context.RepresentativeSet.Select(x => new GetSelectListRepresentativeViewModel() + { + Id = x.id, + Name = x.FullName + }).ToListAsync(); + } + + #endregion } \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Controllers/AdminMonthlyOverviewController.cs b/ServiceHost/Areas/Admin/Controllers/AdminMonthlyOverviewController.cs new file mode 100644 index 00000000..ed83b3fb --- /dev/null +++ b/ServiceHost/Areas/Admin/Controllers/AdminMonthlyOverviewController.cs @@ -0,0 +1,67 @@ +using _0_Framework.Application; +using CompanyManagment.App.Contracts.AdminMonthlyOverview; +using Microsoft.AspNetCore.Mvc; +using ServiceHost.BaseControllers; + +namespace ServiceHost.Api.Areas.Admin.Controllers; + +public class AdminMonthlyOverviewController:AdminController +{ + + private readonly IAdminMonthlyOverviewApplication _adminMonthlyOverviewApplication; + + public AdminMonthlyOverviewController(IAdminMonthlyOverviewApplication adminMonthlyOverviewApplication) + { + _adminMonthlyOverviewApplication = adminMonthlyOverviewApplication; + } + + /// + /// لیست امور ماهیانه پرسنل + /// + /// + /// + [HttpGet("")] + public async Task>> GetList([FromQuery]AdminMonthlyOverviewSearchModel searchModel) + { + var result= await _adminMonthlyOverviewApplication.GetWorkshopListByStatus(searchModel); + return result; + } + + /// + /// مرحله بهدی + /// + /// + /// + [HttpPost("Next/{id}")] + public async Task> Next(long id) + { + var result = await _adminMonthlyOverviewApplication.Next(id); + return result; + } + + /// + /// مرحله قبلی + /// + /// + /// + [HttpPost("Back/{id}")] + public async Task> Back(long id) + { + var result = await _adminMonthlyOverviewApplication.Back(id); + return result; + } + + /// + /// تعداد امور ماهاینه + /// + /// + /// + /// + /// + [HttpGet("Counter")] + public async Task> Counter(int year,int month,int accountId) + { + var result = await _adminMonthlyOverviewApplication.GetCounter(year,month,accountId); + return result; + } +} \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Controllers/EmployeesController.cs b/ServiceHost/Areas/Admin/Controllers/EmployeesController.cs new file mode 100644 index 00000000..dc05bcd6 --- /dev/null +++ b/ServiceHost/Areas/Admin/Controllers/EmployeesController.cs @@ -0,0 +1,40 @@ +using _0_Framework.Application; +using CompanyManagment.App.Contracts.Employee; +using Microsoft.AspNetCore.Mvc; +using ServiceHost.BaseControllers; + +namespace ServiceHost.Api.Areas.Admin.Controllers; + +public class EmployeesController:AdminController +{ + private readonly IEmployeeApplication _employeeApplication; + private readonly IAuthHelper _authHelper; + public EmployeesController(IEmployeeApplication employeeApplication, IAuthHelper authHelper) + { + _employeeApplication = employeeApplication; + _authHelper = authHelper; + } + + + + /// + /// لیست پرسنل برای جستجو + /// + /// + /// + [HttpGet("select_list")] + public async Task>> GetSelectList(string searchText) + { + var data = await _employeeApplication.GetSelectList(searchText); + + return data; + } + + [HttpGet] + public async Task>> GetList(GetEmployeeListSearchModel searchModel) + { + var result = await _employeeApplication.GetList(searchModel); + + return result; + } +} \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Controllers/EmployerController.cs b/ServiceHost/Areas/Admin/Controllers/EmployerController.cs new file mode 100644 index 00000000..78a7963c --- /dev/null +++ b/ServiceHost/Areas/Admin/Controllers/EmployerController.cs @@ -0,0 +1,123 @@ +using _0_Framework.Application; +using CompanyManagment.App.Contracts.Employer; +using Microsoft.AspNetCore.Mvc; +using ServiceHost.BaseControllers; + +namespace ServiceHost.Areas.Admin.Controllers; + +public class EmployerController : AdminController +{ + private readonly IEmployerApplication _employerApplication; + + public EmployerController(IEmployerApplication employerApplication) + { + _employerApplication = employerApplication; + } + + + /// + /// لیست کارفرما + /// + /// + /// + [HttpGet] + public async Task>> GetList(GetEmployerSearchModel searchModel) + { + return await _employerApplication.GetEmployerList(searchModel); + } + + /// + /// جزئیات کارفرمای حقوقی + /// + /// + /// + [HttpGet("legal/{id}")] + public async Task> GetLegalEmployer(long id) + { + var employerDetail = await _employerApplication.GetLegalEmployerDetail(id); + return employerDetail; + } + + /// + /// جزئیات کارفرمای حقیقی + /// + /// + /// + [HttpGet("real/{id}")] + public async Task> GetRealEmployer(long id) + { + var employerDetail = await _employerApplication.GetRealEmployerDetail(id); + return employerDetail; + } + + /// + /// ایجاد کارفرمای حقیقی + /// + /// + /// + [HttpPost("real")] + public async Task> CreateRealEmployer([FromBody] CreateRealEmployer command) + { + var result = await _employerApplication.CreateReal(command); + return result; + } + + /// + /// ایجاد کارفرما حقوقی + /// + /// + /// + [HttpPost("legal")] + public async Task> CreateLegalEmployer([FromBody] CreateLegalEmployer command) + { + var result = await _employerApplication.CreateLegal(command); + + return result; + } + + /// + /// ویرایش کارفرما حقیقی + /// + /// + /// + [HttpPut("real")] + public async Task> EditRealEmployer([FromBody] EditRealEmployer command) + { + var result = await _employerApplication.EditReal(command); + return result; + } + /// + /// ویرایش کارفرما حقوقی + /// + /// + /// + [HttpPut("legal")] + public async Task> EditLegalEmployer([FromBody] EditLegalEmployer command) + { + var result = await _employerApplication.EditLegal(command); + return result; + } + + /// + /// حذف کارفرما - درصورت داشتن کارگاه، کارفرما غیرفعال میشود + /// + /// + /// + [HttpDelete("{id}")] + public async Task>> Remove(long id) + { + var result = await _employerApplication.Remove(id); + return result; + } + + /// + /// سلکت لیست کارفرما برای جستجو + /// + /// + [HttpGet("select_list")] + public async Task> GetSelectList(string search) + { + return await _employerApplication.GetSelectList(search); + } + +} \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Controllers/RepresentativeController.cs b/ServiceHost/Areas/Admin/Controllers/RepresentativeController.cs new file mode 100644 index 00000000..a57876d1 --- /dev/null +++ b/ServiceHost/Areas/Admin/Controllers/RepresentativeController.cs @@ -0,0 +1,151 @@ +using _0_Framework.Application; +using CompanyManagment.App.Contracts.PersonalContractingParty; +using CompanyManagment.App.Contracts.Representative; +using Microsoft.AspNetCore.Mvc; +using ServiceHost.BaseControllers; + +namespace ServiceHost.Areas.Admin.Controllers; + +public class RepresentativeController : AdminController +{ + private readonly IRepresentativeApplication _representativeApplication; + + public RepresentativeController(IRepresentativeApplication representativeApplication) + { + _representativeApplication = representativeApplication; + } + + /// + /// گرفتن لیست معرف ها + /// + /// + /// + [HttpGet] + public async Task>> Get(RepresentativeGetListSearchModel searchModel) + { + return await _representativeApplication.GetList(searchModel); + } + + /// + /// ایجاد معرف حقوقی + /// + /// + /// + [HttpPost("legal")] + public ActionResult CreateLegal([FromBody] CreateLegalRepresentative command) + { + return _representativeApplication.CreateLegal(command); + } + + /// + /// ایجاد معرف حقیقی + /// + /// + /// + [HttpPost("real")] + public ActionResult CreateReal([FromBody] CreateRealRepresentative command) + { + return _representativeApplication.CreateReal(command); + } + + /// + /// گرفتن جزئیات معرف + /// + /// + /// + [HttpGet("{id}")] + public ActionResult GetDetails(long id) + { + return _representativeApplication.GetDetails(id); + } + + /// + /// ویرایش معرف حقوقی + /// + /// + /// + [HttpPut("Legal")] + public ActionResult EditLegal([FromBody] EditLegalRepresentative command) + { + return _representativeApplication.EditLegal(command); + } + + /// + /// ویرایش معرف حقیقی + /// + /// + /// + [HttpPut("Real")] + public ActionResult EditReal([FromBody] EditRealRepresentative command) + { + return _representativeApplication.EditReal(command); + } + + + /// + /// گرفتن لیست طرف حساب ها با آیدی معرف + /// + /// + /// + [HttpGet("contracting_parties/{id}")] + public ActionResult> GetContractingParties(long id) + { + return _representativeApplication.GetContractingParties(id); + } + + /// + /// حذف معرف + /// + /// + /// + [HttpDelete] + public ActionResult Delete(long id) + { + return _representativeApplication.DeleteRepresentative(id); + } + + /// + /// فعال کردن معرف + /// + /// + /// + [HttpPost("active/{id}")] + public ActionResult Active(long id) + { + return _representativeApplication.Active(id); + } + + /// + /// غیرفعال کردن معرف + /// + /// + /// + [HttpPost("deactivate/{id}")] + public ActionResult DeActive(long id) + { + return _representativeApplication.DeActive(id); + } + + /// + /// طرف حسابی دارد یا ندارد + /// + /// + /// + [HttpGet("has_any_contracting_party")] + public ActionResult HasAnyContractingParty(long id) + { + return _representativeApplication.HasAnyContractingParty(id); + } + + + /// + /// سلکت لیست معرف برای سرچ + /// + /// + [HttpGet("select_list")] + public async Task> GetSelectList() + { + return await _representativeApplication.GetSelectList(); + } + +} \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Controllers/WorkshopController.cs b/ServiceHost/Areas/Admin/Controllers/WorkshopController.cs new file mode 100644 index 00000000..099353e2 --- /dev/null +++ b/ServiceHost/Areas/Admin/Controllers/WorkshopController.cs @@ -0,0 +1,28 @@ +using CompanyManagment.App.Contracts.Workshop; +using Microsoft.AspNetCore.Mvc; +using ServiceHost.BaseControllers; + +namespace ServiceHost.Areas.Admin.Controllers; + +public class WorkshopController:AdminController +{ + private readonly IWorkshopApplication _workshopApplication; + + public WorkshopController(IWorkshopApplication workshopApplication) + { + _workshopApplication = workshopApplication; + } + + /// + /// لیست کارگاه برای جستجو + /// + /// + /// + [HttpGet("select_list")] + public async Task>> GetSelectList(string searchText) + { + var data = await _workshopApplication.GetSelectList(searchText); + + return data; + } +} \ No newline at end of file diff --git a/ServiceHost/Program.cs b/ServiceHost/Program.cs index 4ac2a728..ec893e05 100644 --- a/ServiceHost/Program.cs +++ b/ServiceHost/Program.cs @@ -1,5 +1,6 @@ -using System; +using System; using System.Collections.Generic; +using System.Reflection; using _0_Framework.Application.Sms; using _0_Framework.Application; using AccountManagement.Configuration; @@ -17,8 +18,11 @@ using ServiceHost.Hubs; using ServiceHost.MiddleWare; using WorkFlow.Infrastructure.Config; using _0_Framework.Application.UID; +using _0_Framework.Exceptions.Handler; +using Microsoft.OpenApi.Models; using ServiceHost.Test; + var builder = WebApplication.CreateBuilder(args); builder.WebHost.ConfigureKestrel(serverOptions => @@ -36,6 +40,17 @@ builder.Services.AddHttpContextAccessor(); builder.Services.AddHttpClient("holidayApi", c => c.BaseAddress = new System.Uri("https://api.github.com")); var connectionString = builder.Configuration.GetConnectionString("MesbahDb"); var connectionStringTestDb = builder.Configuration.GetConnectionString("TestDb"); + +#region MongoDb + +//var mongoConnectionSection = builder.Configuration.GetSection("MongoDb"); +//var mongoDbSettings = mongoConnectionSection.Get(); +//var mongoClient = new MongoClient(mongoDbSettings.ConnectionString); +//var mongoDatabase = mongoClient.GetDatabase(mongoDbSettings.DatabaseName); + +//builder.Services.AddSingleton(mongoDatabase); + +#endregion PersonalBootstrapper.Configure(builder.Services, connectionString); TestDbBootStrapper.Configure(builder.Services, connectionStringTestDb); AccountManagementBootstrapper.Configure(builder.Services, connectionString); @@ -163,9 +178,98 @@ builder.Services.AddSignalR(); #endregion +#region Swagger +builder.Services.AddSwaggerGen(options => +{ + + var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); + options.IncludeXmlComments(xmlPath); + + // Get XML comments from the class library + var classLibraryXmlFile = "CompanyManagment.App.Contracts.xml"; + var classLibraryXmlPath = Path.Combine(AppContext.BaseDirectory, classLibraryXmlFile); + options.IncludeXmlComments(classLibraryXmlPath); + + + options.SwaggerDoc("General", new OpenApiInfo { Title = "API - General", Version = "v1" }); + options.SwaggerDoc("Admin", new OpenApiInfo { Title = "API - Admin", Version = "v1" }); + options.SwaggerDoc("Client", new OpenApiInfo { Title = "API - Client", Version = "v1" }); + options.SwaggerDoc("Camera", new OpenApiInfo { Title = "API - Camera", Version = "v1" }); + + options.DocInclusionPredicate((docName, apiDesc) => string.Equals(docName, apiDesc.GroupName, StringComparison.OrdinalIgnoreCase)); + + + // اضافه کردن پشتیبانی از JWT در Swagger + options.AddSecurityDefinition("Bearer", new Microsoft.OpenApi.Models.OpenApiSecurityScheme + { + Name = "Authorization", + Type = Microsoft.OpenApi.Models.SecuritySchemeType.ApiKey, + Scheme = "Bearer", + BearerFormat = "JWT", + In = Microsoft.OpenApi.Models.ParameterLocation.Header, + Description = "لطفاً 'Bearer [space] token' را وارد کنید." + }); + + options.AddSecurityRequirement(new Microsoft.OpenApi.Models.OpenApiSecurityRequirement + { + { + new Microsoft.OpenApi.Models.OpenApiSecurityScheme + { + Reference = new Microsoft.OpenApi.Models.OpenApiReference + { + Type = Microsoft.OpenApi.Models.ReferenceType.SecurityScheme, + Id = "Bearer" + } + }, + Array.Empty() + } + }); + + options.EnableAnnotations(); +}); +#endregion + +#region CORS + +builder.Services.AddCors(options => +{ + options.AddPolicy("AllowSpecificOrigins", policy => + { + policy.WithOrigins("http://localhost:3000", "http://localhost:3001", "https://gozareshgir.ir", "https://dad-mehr.ir") + .AllowAnyHeader() + .AllowAnyMethod() + .AllowCredentials(); + }); +}); + +//builder.Services.AddCors(options => +//{ +// options.AddPolicy("AllowAny", policy => +// { +// policy.AllowAnyOrigin() +// .AllowAnyHeader() +// .AllowAnyMethod(); +// }); +// options.AddPolicy("AllowSpecificOrigins", policy => +// { +// policy.WithOrigins("http://localhost:3000", "http://localhost:3001", "https://gozareshgir.ir", "https://dad-mehr.ir") +// .AllowAnyHeader() +// .AllowAnyMethod() +// .AllowCredentials(); +// }); +//}); +#endregion + +builder.Services.AddExceptionHandler(); + var app = builder.Build(); + +app.UseCors("AllowSpecificOrigins"); + #region Mahan -app.UseStatusCodePagesWithRedirects("/error/{0}"); + +//app.UseStatusCodePagesWithRedirects("/error/{0}"); //the backend Tester if (builder.Environment.IsDevelopment()) @@ -175,6 +279,17 @@ if (builder.Environment.IsDevelopment()) await tester.Test(); } +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(options => + { + options.SwaggerEndpoint("/swagger/General/swagger.json", "API - General"); + options.SwaggerEndpoint("/swagger/Admin/swagger.json", "API - Admin"); + options.SwaggerEndpoint("/swagger/Client/swagger.json", "API - Client"); + options.SwaggerEndpoint("/swagger/Camera/swagger.json", "API - Camera"); + }); +} #endregion //Create Http Pipeline diff --git a/ServiceHost/ServiceHost.csproj b/ServiceHost/ServiceHost.csproj index d03e3d54..a6d7e7e7 100644 --- a/ServiceHost/ServiceHost.csproj +++ b/ServiceHost/ServiceHost.csproj @@ -3,8 +3,10 @@ net8.0 enable + true - + + true @@ -88,6 +90,8 @@ + +