From 5576ee5c2420ef8d98d24abe70a1ac5a897e5a7f Mon Sep 17 00:00:00 2001 From: SamSys Date: Fri, 30 May 2025 23:04:53 +0330 Subject: [PATCH] api started --- .../Application/Enums/ActivationStatus.cs | 8 + 0_Framework/Application/Enums/Gender.cs | 8 + 0_Framework/Application/Enums/LegalType.cs | 8 + .../Application/SelectListViewModel.cs | 7 + .../IPersonalContractingPartyRepository.cs | 29 ++ .../ContractingPartyGetListSearchModel.cs | 37 ++ .../ContractingPartyGetListViewModel.cs | 60 ++++ .../ContractingPartySelectListViewModel.cs | 8 + .../CreateLegalContractingParty.cs | 74 ++++ .../CreateRealContractingParty.cs | 77 +++++ .../EditLegalContractingParty.cs | 12 + .../EditRealContractingParty.cs | 13 + ...gPartyNationalCodeOrNationalIdViewModel.cs | 12 + ...etLegalContractingPartyDetailsViewModel.cs | 83 +++++ ...GetRealContractingPartyDetailsViewModel.cs | 94 ++++++ .../IPersonalContractingPartyApp.cs | 76 +++++ .../PersonalContractingPartyViewModel.cs | 2 + .../PersonalContractingPartyApplication.cs | 316 +++++++++++++++--- .../PersonalContractingPartyRepository.cs | 245 ++++++++++++++ .../Controllers/ContractingPartyController.cs | 173 ++++++++++ .../BaseControllers/AdminController.cs | 12 + ServiceHost/Program.cs | 6 + 22 files changed, 1312 insertions(+), 48 deletions(-) create mode 100644 0_Framework/Application/Enums/ActivationStatus.cs create mode 100644 0_Framework/Application/Enums/Gender.cs create mode 100644 0_Framework/Application/Enums/LegalType.cs create mode 100644 0_Framework/Application/SelectListViewModel.cs create mode 100644 CompanyManagment.App.Contracts/PersonalContractingParty/ContractingPartyGetListSearchModel.cs create mode 100644 CompanyManagment.App.Contracts/PersonalContractingParty/ContractingPartyGetListViewModel.cs create mode 100644 CompanyManagment.App.Contracts/PersonalContractingParty/ContractingPartySelectListViewModel.cs create mode 100644 CompanyManagment.App.Contracts/PersonalContractingParty/CreateLegalContractingParty.cs create mode 100644 CompanyManagment.App.Contracts/PersonalContractingParty/CreateRealContractingParty.cs create mode 100644 CompanyManagment.App.Contracts/PersonalContractingParty/EditLegalContractingParty.cs create mode 100644 CompanyManagment.App.Contracts/PersonalContractingParty/EditRealContractingParty.cs create mode 100644 CompanyManagment.App.Contracts/PersonalContractingParty/GetContractingPartyNationalCodeOrNationalIdViewModel.cs create mode 100644 CompanyManagment.App.Contracts/PersonalContractingParty/GetLegalContractingPartyDetailsViewModel.cs create mode 100644 CompanyManagment.App.Contracts/PersonalContractingParty/GetRealContractingPartyDetailsViewModel.cs create mode 100644 ServiceHost/Areas/Admin/Controllers/ContractingPartyController.cs create mode 100644 ServiceHost/BaseControllers/AdminController.cs diff --git a/0_Framework/Application/Enums/ActivationStatus.cs b/0_Framework/Application/Enums/ActivationStatus.cs new file mode 100644 index 00000000..c125f5bd --- /dev/null +++ b/0_Framework/Application/Enums/ActivationStatus.cs @@ -0,0 +1,8 @@ +namespace _0_Framework.Application.Enums; + +public enum ActivationStatus +{ + None = 0, + Active = 1, + DeActive = 2 +} \ No newline at end of file diff --git a/0_Framework/Application/Enums/Gender.cs b/0_Framework/Application/Enums/Gender.cs new file mode 100644 index 00000000..1b4077ca --- /dev/null +++ b/0_Framework/Application/Enums/Gender.cs @@ -0,0 +1,8 @@ +namespace _0_Framework.Application.Enums; + +public enum Gender +{ + None, + Male, + Female +} \ No newline at end of file diff --git a/0_Framework/Application/Enums/LegalType.cs b/0_Framework/Application/Enums/LegalType.cs new file mode 100644 index 00000000..779cdccc --- /dev/null +++ b/0_Framework/Application/Enums/LegalType.cs @@ -0,0 +1,8 @@ +namespace _0_Framework.Application.Enums; + +public enum LegalType +{ + None = 0, + Real = 1, + Legal = 2 +} \ No newline at end of file diff --git a/0_Framework/Application/SelectListViewModel.cs b/0_Framework/Application/SelectListViewModel.cs new file mode 100644 index 00000000..2262df1a --- /dev/null +++ b/0_Framework/Application/SelectListViewModel.cs @@ -0,0 +1,7 @@ +namespace _0_Framework.Application; + +public class SelectListViewModel +{ + public long Id { get; set; } + public string Text { get; set; } +} \ No newline at end of file diff --git a/Company.Domain/ContarctingPartyAgg/IPersonalContractingPartyRepository.cs b/Company.Domain/ContarctingPartyAgg/IPersonalContractingPartyRepository.cs index 0ba87c2d..17e588a8 100644 --- a/Company.Domain/ContarctingPartyAgg/IPersonalContractingPartyRepository.cs +++ b/Company.Domain/ContarctingPartyAgg/IPersonalContractingPartyRepository.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using _0_Framework.Application; using _0_Framework.Domain; using AccountManagement.Application.Contracts.Account; +using System.Threading.Tasks; namespace Company.Domain.ContarctingPartyAgg; @@ -42,6 +43,34 @@ public interface IPersonalContractingPartyRepository :IRepository + /// لیست طرف حساب ها + /// + /// + /// + Task> GetList(ContractingPartyGetListSearchModel searchModel); + /// + /// لیست طرف حساب برای سلکت لیست سرچ + /// + /// + Task> GetSelectList(); + + /// + /// لیستی از شماره ملی یا شناسه ملی بر اساس حقیقی یا حقوقی بودن + /// + /// + Task> GetNationalCodeOrNationalId(); + + /// + /// غیرفعال کردن طرف حساب و زیرمجموعه های آن + /// + /// + /// + Task> DeactivateWithSubordinates(long id); + + void Remove(PersonalContractingParty entity); + Task GetRealDetails(long id); + Task GetLegalDetails(long id); } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/PersonalContractingParty/ContractingPartyGetListSearchModel.cs b/CompanyManagment.App.Contracts/PersonalContractingParty/ContractingPartyGetListSearchModel.cs new file mode 100644 index 00000000..fd2f7f9a --- /dev/null +++ b/CompanyManagment.App.Contracts/PersonalContractingParty/ContractingPartyGetListSearchModel.cs @@ -0,0 +1,37 @@ +using _0_Framework.Application.Enums; + +namespace CompanyManagment.App.Contracts.PersonalContractingParty; + +public class ContractingPartyGetListSearchModel +{ + /// + /// تعدادی که برای لیست بعدی آیتم باید رد کنه + /// + public int PageIndex { get; set; } + + /// + /// نام شرکت یا نام و نام خانوادگی طرف حساب + /// + public string FullNameOrCompanyName { get; set; } + + /// + /// شناسه ملی یا شماره ملی + /// + public string NationalIdOrNationalCode { get; set; } + + /// + /// نام معرف + /// + public string RepresentativeName { get; set; } + + /// + /// نوع طرف حساب + /// + public LegalType ContractingPartyType { get; set; } + + /// + /// وضعیت طرف حساب + /// + public ActivationStatus ContractingPartyStatus { get; set; } + +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/PersonalContractingParty/ContractingPartyGetListViewModel.cs b/CompanyManagment.App.Contracts/PersonalContractingParty/ContractingPartyGetListViewModel.cs new file mode 100644 index 00000000..ab435f57 --- /dev/null +++ b/CompanyManagment.App.Contracts/PersonalContractingParty/ContractingPartyGetListViewModel.cs @@ -0,0 +1,60 @@ +using System.Collections.Generic; +using _0_Framework.Application.Enums; + +namespace CompanyManagment.App.Contracts.PersonalContractingParty; + +public record ContractingPartyGetListEmployerViewModel(long EmployerId, string EmployerName); + +public class ContractingPartyGetListViewModel +{ + /// + /// آیدی طرف حساب + /// + public long Id { get; set; } + + /// + /// کد طرف حساب + /// + public int ArchiveCode { get; set; } + + /// + /// شناسه ملی یا شماره ملی + /// + public string NationalIdOrNationalCode { get; set; } + + /// + /// نام طرف حساب + /// + public string ContractingPartyName { get; set; } + + /// + /// لیست کارفرما ها + /// + public ICollection Employers { get; set; } + + /// + /// تعداد بلاک + /// + public int BlockTimes { get; set; } + + /// + /// آیا بلاک هست + /// + public bool IsBlock { get; set; } + + /// + /// آیا دارای قرارداد مالی است + /// + public bool HasInstitutionContract { get; set; } + + /// + /// نوع طرف حساب + /// + public LegalType ContractingPartyType { get; set; } + + /// + /// وضعیت طرف حساب + /// + public ActivationStatus Status { get; set; } + +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/PersonalContractingParty/ContractingPartySelectListViewModel.cs b/CompanyManagment.App.Contracts/PersonalContractingParty/ContractingPartySelectListViewModel.cs new file mode 100644 index 00000000..29186b6b --- /dev/null +++ b/CompanyManagment.App.Contracts/PersonalContractingParty/ContractingPartySelectListViewModel.cs @@ -0,0 +1,8 @@ +using _0_Framework.Application; + +namespace CompanyManagment.App.Contracts.PersonalContractingParty; + +public class ContractingPartySelectListViewModel: SelectListViewModel +{ + +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/PersonalContractingParty/CreateLegalContractingParty.cs b/CompanyManagment.App.Contracts/PersonalContractingParty/CreateLegalContractingParty.cs new file mode 100644 index 00000000..996070fc --- /dev/null +++ b/CompanyManagment.App.Contracts/PersonalContractingParty/CreateLegalContractingParty.cs @@ -0,0 +1,74 @@ +using System.ComponentModel.DataAnnotations; + +namespace CompanyManagment.App.Contracts.PersonalContractingParty; + +public class CreateLegalContractingParty +{ + /// + /// آیدی معرف + /// + [Required] + public long RepresentativeId { get; set; } + + /// + /// نام شرکت + /// + [Required] + public string CompanyName { get; set; } + + /// + /// شناسه ملی + /// + [Required] + public string NationalId { get; set; } + + /// + /// کد طرف حساب + /// + [Required] + public int ArchiveCode { get; set; } + + /// + /// نام مستعار + /// + public string SureName { get; set; } + + /// + /// شماره ثبت + /// + public string RegisterId { get; set; } + + + + /// + /// شماره تلفن + /// + public string PhoneNumber { get; set; } + + /// + /// شماره تلفن نماینده + /// + public string AgentPhone { get; set; } + + /// + /// استان + /// + public string State { get; set; } + + /// + /// شهر + /// + public string City { get; set; } + + /// + /// محله + /// + public string Zone { get; set; } + + /// + /// نشانی + /// + public string Address { get; set; } + + +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/PersonalContractingParty/CreateRealContractingParty.cs b/CompanyManagment.App.Contracts/PersonalContractingParty/CreateRealContractingParty.cs new file mode 100644 index 00000000..e35fe25c --- /dev/null +++ b/CompanyManagment.App.Contracts/PersonalContractingParty/CreateRealContractingParty.cs @@ -0,0 +1,77 @@ +using System.ComponentModel.DataAnnotations; + +namespace CompanyManagment.App.Contracts.PersonalContractingParty; + +public class CreateRealContractingParty +{ + /// + /// نام + /// + [Required] + public string FName { get; set; } + + /// + /// نام خانوادگی + /// + [Required] + public string LName { get; set; } + + /// + /// آیدی معرف + /// + [Required] + public long RepresentativeId { get; set; } + + /// + /// کد ملی + /// + [Required] + public string NationalCode { get; set; } + + /// + /// شماره شناسنامه + /// + [Required] + public string IdNumber { get; set; } + + /// + /// کد طرف حساب + /// + [Required] + public int ArchiveCode { get; set; } + + /// + /// نام مستعار + /// + public string SureName { get; set; } + + /// + /// شماره تلفن + /// + public string PhoneNumber { get; set; } + + /// + /// شماره تلفن نماینده + /// + public string AgentPhone { get; set; } + + /// + /// استان + /// + public string State { get; set; } + + /// + /// شهر + /// + public string City { get; set; } + + /// + /// محله + /// + public string Zone { get; set; } + + /// + /// نشانی + /// + public string Address { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/PersonalContractingParty/EditLegalContractingParty.cs b/CompanyManagment.App.Contracts/PersonalContractingParty/EditLegalContractingParty.cs new file mode 100644 index 00000000..a55c28da --- /dev/null +++ b/CompanyManagment.App.Contracts/PersonalContractingParty/EditLegalContractingParty.cs @@ -0,0 +1,12 @@ +namespace CompanyManagment.App.Contracts.PersonalContractingParty; + +/// +/// ویرایش طرف حساب حقوقی +/// +public class EditLegalContractingParty:CreateLegalContractingParty +{ + /// + /// آیدی طرف حساب + /// + public long Id { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/PersonalContractingParty/EditRealContractingParty.cs b/CompanyManagment.App.Contracts/PersonalContractingParty/EditRealContractingParty.cs new file mode 100644 index 00000000..04150cc5 --- /dev/null +++ b/CompanyManagment.App.Contracts/PersonalContractingParty/EditRealContractingParty.cs @@ -0,0 +1,13 @@ +namespace CompanyManagment.App.Contracts.PersonalContractingParty; + +/// +/// ویرایش طرف حساب حقیقی +/// +public class EditRealContractingParty:CreateRealContractingParty +{ + /// + /// آیدی طرف حساب + /// + public long Id { get; set; } + +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/PersonalContractingParty/GetContractingPartyNationalCodeOrNationalIdViewModel.cs b/CompanyManagment.App.Contracts/PersonalContractingParty/GetContractingPartyNationalCodeOrNationalIdViewModel.cs new file mode 100644 index 00000000..5258c58a --- /dev/null +++ b/CompanyManagment.App.Contracts/PersonalContractingParty/GetContractingPartyNationalCodeOrNationalIdViewModel.cs @@ -0,0 +1,12 @@ +namespace CompanyManagment.App.Contracts.PersonalContractingParty; + +/// +/// شماره ملی یا شناسه ملی بر اساس حقیقی یا حقوقی بودن +/// +public class GetContractingPartyNationalCodeOrNationalIdViewModel +{ + /// + /// شماره ملی یا شناسه ملی + /// + public string NationalCodeOrNationalId { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/PersonalContractingParty/GetLegalContractingPartyDetailsViewModel.cs b/CompanyManagment.App.Contracts/PersonalContractingParty/GetLegalContractingPartyDetailsViewModel.cs new file mode 100644 index 00000000..787ffec5 --- /dev/null +++ b/CompanyManagment.App.Contracts/PersonalContractingParty/GetLegalContractingPartyDetailsViewModel.cs @@ -0,0 +1,83 @@ +namespace CompanyManagment.App.Contracts.PersonalContractingParty; + +/// +/// ویو مدل جزئیات طرف حساب حقوقی +/// +public class GetLegalContractingPartyDetailsViewModel +{ + /// + /// آیدی طرف حساب + /// + public long Id { get; set; } + + /// + /// نام کامل شرکت(به همراه نام مستعار)ء + /// + public string CompanyFullName { get; set; } + + /// + /// نام شرکت (بدون نام مستعار)ء + /// + public string CompanyName { get; set; } + + /// + /// نام مستعار + /// + public string SureName { get; set; } + + /// + /// شماره ثبت + /// + public string RegisterId { get; set; } + + /// + /// شماره ملی + /// + public string NationalId { get; set; } + + /// + /// شماره تماس + /// + public string PhoneNumber { get; set; } + + /// + /// شماره تماس نماینده + /// + public string AgentPhone { get; set; } + + /// + /// آدرس + /// + public string Address { get; set; } + + /// + /// معرف + /// + public string RepresentativeName { get; set; } + + /// + /// آیدی معرف + /// + public long RepresentativeId { get; set; } + + /// + /// کد طرف حساب + /// + public int ArchiveCode { get; set; } + + /// + /// استان + /// + public string State { get; set; } + + /// + /// شهر + /// + public string City { get; set; } + + /// + /// محله + /// + public string Zone { get; set; } + +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/PersonalContractingParty/GetRealContractingPartyDetailsViewModel.cs b/CompanyManagment.App.Contracts/PersonalContractingParty/GetRealContractingPartyDetailsViewModel.cs new file mode 100644 index 00000000..165871a6 --- /dev/null +++ b/CompanyManagment.App.Contracts/PersonalContractingParty/GetRealContractingPartyDetailsViewModel.cs @@ -0,0 +1,94 @@ +using System.Runtime.CompilerServices; +using Microsoft.AspNetCore.Builder; + +namespace CompanyManagment.App.Contracts.PersonalContractingParty; + +/// +/// ویو مدل جزئیات طرف حساب حقیقی +/// +public class GetRealContractingPartyDetailsViewModel +{ + /// + /// آیدی طرف حساب + /// + public long Id { get; set; } + + /// + /// نام + /// + public string FName { get; set; } + + /// + /// نام خانوادگی + /// + public string LName { get; set; } + + /// + /// نام و نام خانوادگی + /// + public string FullName { get; set; } + + /// + /// کد ملی + /// + public string NationalCode { get; set; } + + /// + /// شماره شناسنامه + /// + public string IdNumber { get; set; } + + /// + /// شماره تلفن + /// + public string PhoneNumber { get; set; } + + /// + /// شماره تلفن نماینده + /// + public string AgentPhone { get; set; } + + /// + /// آدرس + /// + public string Address { get; set; } + + + /// + /// نام معرف + /// + public string RepresentativeName { get; set; } + + /// + /// آیدی معرف + /// + public long RepresentativeId { get; set; } + + /// + /// نام مستعار + /// + public string SureName { get; set; } + + /// + /// کد طرف حساب + /// + public int ArchiveCode { get; set; } + + + /// + /// استان + /// + public string State { get; set; } + + /// + /// شهر + /// + public string City { get; set; } + + /// + /// محله + /// + public string Zone { get; set; } + + +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/PersonalContractingParty/IPersonalContractingPartyApp.cs b/CompanyManagment.App.Contracts/PersonalContractingParty/IPersonalContractingPartyApp.cs index b3303f0a..cfa0bc11 100644 --- a/CompanyManagment.App.Contracts/PersonalContractingParty/IPersonalContractingPartyApp.cs +++ b/CompanyManagment.App.Contracts/PersonalContractingParty/IPersonalContractingPartyApp.cs @@ -1,5 +1,6 @@ using _0_Framework.Application; using System.Collections.Generic; +using System.Threading.Tasks; namespace CompanyManagment.App.Contracts.PersonalContractingParty; @@ -54,4 +55,79 @@ public interface IPersonalContractingPartyApp #endregion + + #region Api + /// + /// لیست طرف حساب ها + /// + /// + /// + Task> GetList(ContractingPartyGetListSearchModel searchModel); + + /// + /// لیست طرف حساب برای سلکت لیست سرچ + /// + /// + Task> GetSelectList(); + + /// + /// ایجاد طرف حساب حقیقی + /// + /// + /// + Task CreateReal(CreateRealContractingParty command); + + /// + /// ایجاد ظرف حساب حقوقی + /// + /// + /// + Task CreateLegal(CreateLegalContractingParty command); + + + /// + /// لیستی از شماره ملی یا شناسه ملی بر اساس حقیقی یا حقوقی بودن + /// + /// + Task> GetNationalCodeOrNationalId(); + + + /// + /// حذف طرف حساب. در صورتی که طرف حساب دارای قرارداد مالی یا دارای کارفرما باشد غیرفعال میشود + /// + /// + /// + Task> Delete(long id); + + /// + /// ویرایش طرف حساب حقیقی + /// + /// + /// + OperationResult EditRealApi(EditRealContractingParty command); + + + /// + /// ویرایش طرف حساب حقوقی + /// + /// + /// + OperationResult EditLegal(EditLegalContractingParty command); + + /// + /// گرفتن جزئیات طرف حساب حقوقی + /// + /// + /// + Task GetRealDetails(long id); + + /// + /// گرفتن جزئیات طرف حساب حقوقی + /// + /// + /// + Task GetLegalDetails(long id); + + #endregion + } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/PersonalContractingParty/PersonalContractingPartyViewModel.cs b/CompanyManagment.App.Contracts/PersonalContractingParty/PersonalContractingPartyViewModel.cs index c2e955b2..44cc96b2 100644 --- a/CompanyManagment.App.Contracts/PersonalContractingParty/PersonalContractingPartyViewModel.cs +++ b/CompanyManagment.App.Contracts/PersonalContractingParty/PersonalContractingPartyViewModel.cs @@ -47,4 +47,6 @@ public class PersonalContractingPartyViewModel public bool IsAuthenticated { get; set; } public List EmployerList { get; set; } + + } \ No newline at end of file diff --git a/CompanyManagment.Application/PersonalContractingPartyApplication.cs b/CompanyManagment.Application/PersonalContractingPartyApplication.cs index df060edf..d44162ff 100644 --- a/CompanyManagment.Application/PersonalContractingPartyApplication.cs +++ b/CompanyManagment.Application/PersonalContractingPartyApplication.cs @@ -1,17 +1,19 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using _0_Framework.Application; using CompanyManagment.App.Contracts.PersonalContractingParty; using Company.Domain.ContarctingPartyAgg; using Company.Domain.empolyerAgg; using CompanyManagment.App.Contracts.Representative; using Company.Domain.InstitutionContractAgg; +using CompanyManagment.EFCore.Repository; namespace CompanyManagment.Application; public class PersonalContractingPartyApplication : IPersonalContractingPartyApp { - private readonly IPersonalContractingPartyRepository _personalContractingPartyRepository2; + private readonly IPersonalContractingPartyRepository _personalContractingPartyRepository; private readonly IRepresentativeApplication _representativeApplication; private readonly IEmployerRepository _employerRepository; private readonly IInstitutionContractRepository _institutionContractRepository; @@ -26,7 +28,7 @@ public class PersonalContractingPartyApplication : IPersonalContractingPartyApp public PersonalContractingPartyApplication( IPersonalContractingPartyRepository personalContractingPartyRepository, IRepresentativeApplication representativeApplication, IEmployerRepository employerRepository, IInstitutionContractRepository institutionContractRepository) { - _personalContractingPartyRepository2 = personalContractingPartyRepository; + _personalContractingPartyRepository = personalContractingPartyRepository; _representativeApplication = representativeApplication; _employerRepository = employerRepository; _institutionContractRepository = institutionContractRepository; @@ -36,7 +38,7 @@ public class PersonalContractingPartyApplication : IPersonalContractingPartyApp public OperationResult Create(CreatePersonalContractingParty command) { var opration = new OperationResult(); - if (_personalContractingPartyRepository2.Exists(x => + if (_personalContractingPartyRepository.Exists(x => x.LName == command.LName && x.Nationalcode == command.Nationalcode && x.SureName == command.SureName )) return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد"); if (command.RepresentativeId < 1) @@ -54,14 +56,14 @@ public class PersonalContractingPartyApplication : IPersonalContractingPartyApp // return opration.Failed("نام خانوادگی وارد شده تکراری است"); //} - if (_personalContractingPartyRepository2.Exists(x => x.Nationalcode == command.Nationalcode && x.LName != command.LName)) + if (_personalContractingPartyRepository.Exists(x => x.Nationalcode == command.Nationalcode && x.LName != command.LName)) { nationalcodeIsOk = false; return opration.Failed("کد ملی وارد شده تکراری است"); } - if (_personalContractingPartyRepository2.Exists(x => x.ArchiveCode == command.ArchiveCode)) + if (_personalContractingPartyRepository.Exists(x => x.ArchiveCode == command.ArchiveCode)) return opration.Failed("کد طرف حساب تکراری است"); try @@ -132,8 +134,8 @@ public class PersonalContractingPartyApplication : IPersonalContractingPartyApp command.State,command.City,command.Zone,command.SureName); - _personalContractingPartyRepository2.Create(personalContractingParty); - _personalContractingPartyRepository2.SaveChanges(); + _personalContractingPartyRepository.Create(personalContractingParty); + _personalContractingPartyRepository.SaveChanges(); return opration.Succcedded(); @@ -152,13 +154,13 @@ public class PersonalContractingPartyApplication : IPersonalContractingPartyApp public OperationResult Edit2(EditPersonalContractingParty command) { var opration = new OperationResult(); - var personalContractingParty = _personalContractingPartyRepository2.Get(command.Id); + var personalContractingParty = _personalContractingPartyRepository.Get(command.Id); if (personalContractingParty == null) return opration.Failed("رکورد مورد نظر یافت نشد"); personalContractingParty.Edit2(command.Address); - _personalContractingPartyRepository2.SaveChanges(); + _personalContractingPartyRepository.SaveChanges(); return opration.Succcedded(); } @@ -166,7 +168,7 @@ public class PersonalContractingPartyApplication : IPersonalContractingPartyApp { var opration = new OperationResult(); - if (_personalContractingPartyRepository2.Exists(x => + if (_personalContractingPartyRepository.Exists(x => x.LName == command.LName && x.RegisterId == command.RegisterId && x.SureName == command.SureName)) return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد"); if (command.RepresentativeId < 1) @@ -174,23 +176,23 @@ public class PersonalContractingPartyApplication : IPersonalContractingPartyApp - if (_personalContractingPartyRepository2.Exists(x => x.LName == command.LName && x.SureName == command.SureName)) + if (_personalContractingPartyRepository.Exists(x => x.LName == command.LName && x.SureName == command.SureName)) { legalNameIsOk = false; return opration.Failed("نام شرکت وارد شده تکراری است"); } - if (_personalContractingPartyRepository2.Exists(x => x.RegisterId == command.RegisterId && x.LName != command.LName)) + if (_personalContractingPartyRepository.Exists(x => x.RegisterId == command.RegisterId && x.LName != command.LName)) { registerIdIsOk = false; return opration.Failed("شماره ثبت وارد شده تکراری است"); } - if (_personalContractingPartyRepository2.Exists(x => x.NationalId == command.NationalId && x.LName != command.LName)) + if (_personalContractingPartyRepository.Exists(x => x.NationalId == command.NationalId && x.LName != command.LName)) { nationalIdIsOk = false; return opration.Failed("شناسه ملی وارد شده تکراری است"); } - if (_personalContractingPartyRepository2.Exists(x => x.ArchiveCode == command.ArchiveCode)) + if (_personalContractingPartyRepository.Exists(x => x.ArchiveCode == command.ArchiveCode)) return opration.Failed("کد طرف حساب تکراری است"); @@ -204,8 +206,8 @@ public class PersonalContractingPartyApplication : IPersonalContractingPartyApp command.State, command.City, command.Zone,command.SureName); - _personalContractingPartyRepository2.Create(legalContractingParty); - _personalContractingPartyRepository2.SaveChanges(); + _personalContractingPartyRepository.Create(legalContractingParty); + _personalContractingPartyRepository.SaveChanges(); return opration.Succcedded(); @@ -223,15 +225,15 @@ public class PersonalContractingPartyApplication : IPersonalContractingPartyApp { var opration = new OperationResult(); - var personalContractingParty = _personalContractingPartyRepository2.Get(command.Id); + var personalContractingParty = _personalContractingPartyRepository.Get(command.Id); if (personalContractingParty == null) return opration.Failed("رکورد مورد نظر یافت نشد"); if (command.RepresentativeId < 1) return opration.Failed("لطفا معرف را انتخاب کنید"); - if (_personalContractingPartyRepository2.Exists(x => + if (_personalContractingPartyRepository.Exists(x => x.LName == command.LName && x.Nationalcode == command.Nationalcode && x.SureName == command.SureName && x.id != command.Id)) return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد"); - if (_personalContractingPartyRepository2.Exists(x => x.ArchiveCode == command.ArchiveCode && x.id != command.Id)) + if (_personalContractingPartyRepository.Exists(x => x.ArchiveCode == command.ArchiveCode && x.id != command.Id)) return opration.Failed("کد طرف حساب تکراری است"); try { @@ -300,7 +302,7 @@ public class PersonalContractingPartyApplication : IPersonalContractingPartyApp command.Phone, command.AgentPhone, command.Address, command.RepresentativeId, representative.FullName, command.ArchiveCode, command.State, command.City, command.Zone,command.SureName); - _personalContractingPartyRepository2.SaveChanges(); + _personalContractingPartyRepository.SaveChanges(); return opration.Succcedded(); } else @@ -314,16 +316,16 @@ public class PersonalContractingPartyApplication : IPersonalContractingPartyApp { var opration = new OperationResult(); - var legalContractingParty = _personalContractingPartyRepository2.Get(command.Id); + var legalContractingParty = _personalContractingPartyRepository.Get(command.Id); if (legalContractingParty == null) return opration.Failed("رکورد مورد نظر یافت نشد"); - if (_personalContractingPartyRepository2.Exists(x => + if (_personalContractingPartyRepository.Exists(x => x.LName== command.LName && x.RegisterId == command.RegisterId &&x.SureName == command.SureName &&x.id != command.Id)) return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد"); if (command.RepresentativeId < 1) return opration.Failed("لطفا معرف را انتخاب کنید"); - if (_personalContractingPartyRepository2.Exists(x => x.ArchiveCode == command.ArchiveCode && x.id != command.Id)) + if (_personalContractingPartyRepository.Exists(x => x.ArchiveCode == command.ArchiveCode && x.id != command.Id)) return opration.Failed("کد طرف حساب تکراری است"); var representative = _representativeApplication.GetDetails(command.RepresentativeId); legalContractingParty.EditLegal(command.LName, command.RegisterId, @@ -331,54 +333,54 @@ public class PersonalContractingPartyApplication : IPersonalContractingPartyApp command.Phone, command.AgentPhone, command.Address, command.RepresentativeId, representative.FullName,command.ArchiveCode, command.State, command.City, command.Zone, command.SureName); - _personalContractingPartyRepository2.SaveChanges(); + _personalContractingPartyRepository.SaveChanges(); return opration.Succcedded(); } public EditPersonalContractingParty GetDetails(long id) { - return _personalContractingPartyRepository2.GetDetails(id); + return _personalContractingPartyRepository.GetDetails(id); } public string IsBlockByEmployerId(long employerId) { - return _personalContractingPartyRepository2.IsBlockByEmployerId(employerId); + return _personalContractingPartyRepository.IsBlockByEmployerId(employerId); } public EditPersonalContractingParty GetDetailsToEdit(long id) { - return _personalContractingPartyRepository2.GetDetailsToEdit(id); + return _personalContractingPartyRepository.GetDetailsToEdit(id); } public string GetFullName(long id) { - return _personalContractingPartyRepository2.GetFullName(id); + return _personalContractingPartyRepository.GetFullName(id); } public List GetPersonalContractingParties() { - return _personalContractingPartyRepository2.GetPersonalContractingParties(); + return _personalContractingPartyRepository.GetPersonalContractingParties(); } public List Search(PersonalContractingPartySearchModel searchModel2) { - return _personalContractingPartyRepository2.Search(searchModel2); + return _personalContractingPartyRepository.Search(searchModel2); } public int GetLastArchiveCode() { - return _personalContractingPartyRepository2.GetLastArchiveCode(); + return _personalContractingPartyRepository.GetLastArchiveCode(); } #region Mahan public List SearchByName(string name) { - return _personalContractingPartyRepository2.SearchByName(name); + return _personalContractingPartyRepository.SearchByName(name); } #endregion public ContractingPartyAndStatmentIdViewModel GetContractingpartyIdByAccountId(long accountId) { - return _personalContractingPartyRepository2.GetContractingpartyIdByAccountId(accountId); + return _personalContractingPartyRepository.GetContractingpartyIdByAccountId(accountId); } @@ -386,15 +388,15 @@ public class PersonalContractingPartyApplication : IPersonalContractingPartyApp public List GetPersonalContractingPartiesForNationalcode(string searchText) { - return _personalContractingPartyRepository2.GetPersonalContractingPartiesForNationalcode(searchText); + return _personalContractingPartyRepository.GetPersonalContractingPartiesForNationalcode(searchText); } public List SearchForMain(PersonalContractingPartySearchModel searchModel2) { - var result= _personalContractingPartyRepository2.SearchForMain(searchModel2); + var result= _personalContractingPartyRepository.SearchForMain(searchModel2); foreach (var item in result) { - item.HasInstitutionContract = _personalContractingPartyRepository2.GetHasContract(item.id); + item.HasInstitutionContract = _personalContractingPartyRepository.GetHasContract(item.id); } return result; } @@ -411,12 +413,12 @@ public class PersonalContractingPartyApplication : IPersonalContractingPartyApp //اونهایی که کارفرما یا قرارداد غیر فعال دارند غیر فعال می شوند if (_employerRepository.Exists(x => x.ContractingPartyId == id)|| _institutionContractRepository.Exists(x => x.ContractingPartyId == id)) { - opration= _personalContractingPartyRepository2.DeActiveAll(id); + opration= _personalContractingPartyRepository.DeActiveAll(id); return opration; } else { - opration = _personalContractingPartyRepository2.DeletePersonalContractingParties(id); + opration = _personalContractingPartyRepository.DeletePersonalContractingParties(id); } return opration; @@ -428,10 +430,10 @@ public class PersonalContractingPartyApplication : IPersonalContractingPartyApp { var opration = new OperationResult(); - var contract = _personalContractingPartyRepository2.Get(id); + var contract = _personalContractingPartyRepository.Get(id); if (contract == null) return opration.Failed("رکورد مورد نظر یافت نشد"); - return _personalContractingPartyRepository2.ActiveAll(id); + return _personalContractingPartyRepository.ActiveAll(id); //var opration = new OperationResult(); @@ -446,44 +448,44 @@ public class PersonalContractingPartyApplication : IPersonalContractingPartyApp public OperationResult DeActive(long id) { var opration = new OperationResult(); - var personalContracting = _personalContractingPartyRepository2.Get(id); + var personalContracting = _personalContractingPartyRepository.Get(id); if (personalContracting == null) return opration.Failed("رکورد مورد نظر یافت نشد"); personalContracting.DeActive(); - _personalContractingPartyRepository2.SaveChanges(); + _personalContractingPartyRepository.SaveChanges(); return opration.Succcedded(); } public bool GetHasContract(long id) { - return _personalContractingPartyRepository2.GetHasContract(id); + return _personalContractingPartyRepository.GetHasContract(id); } public OperationResult Block(long id) { var opration = new OperationResult(); - var contract = _personalContractingPartyRepository2.Get(id); + var contract = _personalContractingPartyRepository.Get(id); if (contract == null) return opration.Failed("رکورد مورد نظر یافت نشد"); contract.Block(); - _personalContractingPartyRepository2.SaveChanges(); + _personalContractingPartyRepository.SaveChanges(); return opration.Succcedded(); } public OperationResult DisableBlock(long id) { var opration = new OperationResult(); - var personalContracting = _personalContractingPartyRepository2.Get(id); + var personalContracting = _personalContractingPartyRepository.Get(id); if (personalContracting == null) return opration.Failed("رکورد مورد نظر یافت نشد"); int blockTimes = personalContracting.BlockTimes + 1; personalContracting.DisableBlock(blockTimes); - _personalContractingPartyRepository2.SaveChanges(); + _personalContractingPartyRepository.SaveChanges(); @@ -499,7 +501,225 @@ public class PersonalContractingPartyApplication : IPersonalContractingPartyApp public bool IsBlockCheckByWorkshopId(long workshopId) { - return _personalContractingPartyRepository2.IsBlockCheckByWorkshopId(workshopId); + return _personalContractingPartyRepository.IsBlockCheckByWorkshopId(workshopId); + } + + + + #endregion + + + #region Api + + + public async Task> GetList( + ContractingPartyGetListSearchModel searchModel) + { + return await _personalContractingPartyRepository.GetList(searchModel); + } + + public async Task> GetSelectList() + { + return await _personalContractingPartyRepository.GetSelectList(); + } + public async Task CreateReal(CreateRealContractingParty command) + { + var operation = new OperationResult(); + + if (_personalContractingPartyRepository.Exists(x => + x.LName == command.LName && x.Nationalcode == command.NationalCode && x.SureName == command.SureName)) + return operation.Failed("امکان ثبت رکورد تکراری وجود ندارد"); + + if (command.RepresentativeId < 1) + return operation.Failed("لطفا معرف را انتخاب کنید"); + + if (_personalContractingPartyRepository.Exists(x => x.Nationalcode == command.NationalCode && x.LName != command.LName)) + { + nationalcodeIsOk = false; + + return operation.Failed("کد ملی وارد شده تکراری است"); + } + + + if (_personalContractingPartyRepository.Exists(x => x.ArchiveCode == command.ArchiveCode)) + return operation.Failed("کد طرف حساب تکراری است"); + + if (command.NationalCode.NationalCodeValid() != "valid") + { + return operation.Failed("کد ملی وارد شده نا معتبر است"); + } + + var representative = _representativeApplication.GetDetails(command.RepresentativeId); + var personalContractingParty = new PersonalContractingParty(command.FName, command.LName, + command.NationalCode, command.IdNumber, "*", "*", + "حقیقی", + command.PhoneNumber, command.AgentPhone, command.Address, command.RepresentativeId, representative.FullName, command.ArchiveCode, + command.State, command.City, command.Zone, command.SureName); + + + await _personalContractingPartyRepository.CreateAsync(personalContractingParty); + await _personalContractingPartyRepository.SaveChangesAsync(); + + return operation.Succcedded(); + } + + public async Task CreateLegal(CreateLegalContractingParty command) + { + var opration = new OperationResult(); + + if (_personalContractingPartyRepository.Exists(x => + x.LName == command.CompanyName && x.RegisterId == command.RegisterId && x.SureName == command.SureName)) + return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد"); + + if (command.RepresentativeId < 1) + return opration.Failed("لطفا معرف را انتخاب کنید"); + + if (_personalContractingPartyRepository.Exists(x => + x.LName == command.CompanyName && x.SureName == command.SureName)) + { + legalNameIsOk = false; + return opration.Failed("نام شرکت وارد شده تکراری است"); + } + + if (_personalContractingPartyRepository.Exists(x => + x.RegisterId == command.RegisterId && x.LName != command.CompanyName)) + { + registerIdIsOk = false; + return opration.Failed("شماره ثبت وارد شده تکراری است"); + + } + + if (_personalContractingPartyRepository.Exists(x => + x.NationalId == command.NationalId && x.LName != command.CompanyName)) + { + nationalIdIsOk = false; + return opration.Failed("شناسه ملی وارد شده تکراری است"); + } + + if (_personalContractingPartyRepository.Exists(x => x.ArchiveCode == command.ArchiveCode)) + return opration.Failed("کد طرف حساب تکراری است"); + + + + var representative = _representativeApplication.GetDetails(command.RepresentativeId); + var legalContractingParty = new PersonalContractingParty("*", command.CompanyName, + "*", "*", command.RegisterId, command.NationalId, + "حقوقی", + command.PhoneNumber, command.AgentPhone, command.Address, command.RepresentativeId, representative.FullName, + command.ArchiveCode, + command.State, command.City, command.Zone, command.SureName); + + + await _personalContractingPartyRepository.CreateAsync(legalContractingParty); + await _personalContractingPartyRepository.SaveChangesAsync(); + + return opration.Succcedded(); + + } + + public async Task> GetNationalCodeOrNationalId() + { + return await _personalContractingPartyRepository.GetNationalCodeOrNationalId(); + } + + public async Task> Delete(long id) + { + var operationResult = new OperationResult(); + + try + { + //اگر دارای قرارداد یا دازای کارفرما باشد غیر فعال می شود + if (_employerRepository.Exists(x => x.ContractingPartyId == id) || _institutionContractRepository.Exists(x => x.ContractingPartyId == id)) + { + operationResult = await _personalContractingPartyRepository.DeactivateWithSubordinates(id); + return operationResult; + } + + var entity = _personalContractingPartyRepository.Get(id); + _personalContractingPartyRepository.Remove(entity); + operationResult.Succcedded("Deleted"); + } + catch + { + return operationResult.Failed("خطایی رخ داده است"); + } + + return operationResult; + } + + public OperationResult EditRealApi(EditRealContractingParty command) + { + var opration = new OperationResult(); + var personalContractingParty = _personalContractingPartyRepository.Get(command.Id); + + if (personalContractingParty == null) + return opration.Failed("رکورد مورد نظر یافت نشد"); + + if (command.RepresentativeId < 1) + return opration.Failed("لطفا معرف را انتخاب کنید"); + + if (_personalContractingPartyRepository.Exists(x => + x.LName == command.LName && x.Nationalcode == command.NationalCode && x.SureName == command.SureName && x.id != command.Id)) + return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد"); + + if (_personalContractingPartyRepository.Exists(x => x.ArchiveCode == command.ArchiveCode && x.id != command.Id)) + return opration.Failed("کد طرف حساب تکراری است"); + + if (command.NationalCode.NationalCodeValid() != "valid") + { + return opration.Failed("کد ملی وارد شده نا معتبر است"); + } + + try + { + var representative = _representativeApplication.GetDetails(command.RepresentativeId); + personalContractingParty.Edit(command.FName, command.LName, + command.NationalCode, command.IdNumber, + command.PhoneNumber, command.AgentPhone, command.Address, command.RepresentativeId, representative.FullName, command.ArchiveCode, + command.State, command.City, command.Zone, command.SureName); + + _personalContractingPartyRepository.SaveChanges(); + return opration.Succcedded(); + } + catch + { + + return opration.Failed("خطایی رخ داده است"); + } + } + + public OperationResult EditLegal(EditLegalContractingParty command) + { + var opration = new OperationResult(); + var legalContractingParty = _personalContractingPartyRepository.Get(command.Id); + if (legalContractingParty == null) + return opration.Failed("رکورد مورد نظر یافت نشد"); + + if (_personalContractingPartyRepository.Exists(x => + x.LName == command.CompanyName && x.RegisterId == command.RegisterId && x.SureName == command.SureName && x.id != command.Id)) + return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد"); + if (command.RepresentativeId < 1) + return opration.Failed("لطفا معرف را انتخاب کنید"); + if (_personalContractingPartyRepository.Exists(x => x.ArchiveCode == command.ArchiveCode && x.id != command.Id)) + return opration.Failed("کد طرف حساب تکراری است"); + var representative = _representativeApplication.GetDetails(command.RepresentativeId); + legalContractingParty.EditLegal(command.CompanyName, command.RegisterId, + command.NationalId, + command.PhoneNumber, command.AgentPhone, command.Address, command.RepresentativeId, representative.FullName, command.ArchiveCode, + command.State, command.City, command.Zone, command.SureName); + + _personalContractingPartyRepository.SaveChanges(); + return opration.Succcedded(); + } + + public async Task GetRealDetails(long id) + { + return await _personalContractingPartyRepository.GetRealDetails(id); + } + + public async Task GetLegalDetails(long id) + { + return await _personalContractingPartyRepository.GetLegalDetails(id); } #endregion diff --git a/CompanyManagment.EFCore/Repository/PersonalContractingPartyRepository.cs b/CompanyManagment.EFCore/Repository/PersonalContractingPartyRepository.cs index 8dac98a2..6d9bfaba 100644 --- a/CompanyManagment.EFCore/Repository/PersonalContractingPartyRepository.cs +++ b/CompanyManagment.EFCore/Repository/PersonalContractingPartyRepository.cs @@ -1,7 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using _0_Framework.Application; +using _0_Framework.Application.Enums; +using _0_Framework.Exceptions; using _0_Framework.InfraStructure; using AccountManagement.Application.Contracts.Account; using AccountMangement.Infrastructure.EFCore; @@ -478,6 +481,248 @@ public class PersonalContractingPartyRepository : RepositoryBase> GetList(ContractingPartyGetListSearchModel searchModel) + { + var personalContractingPartiesQuery = _context.PersonalContractingParties + .Include(x => x.Representative) + .Include(x => x.Employers).AsQueryable(); + + + + if (!string.IsNullOrWhiteSpace(searchModel.NationalIdOrNationalCode)) + personalContractingPartiesQuery = personalContractingPartiesQuery + .Where(x => x.Nationalcode.Contains(searchModel.NationalIdOrNationalCode) || + x.NationalId.Contains(searchModel.NationalIdOrNationalCode)); + + + if (searchModel.ContractingPartyType != LegalType.None) + + { + string type = searchModel.ContractingPartyType switch + { + LegalType.Legal => "حقوقی", + LegalType.Real => "حقیقی", + _ => "" + }; + + personalContractingPartiesQuery = personalContractingPartiesQuery + .Where(x => x.IsLegal == type); + + } + + + if (searchModel.ContractingPartyStatus != ActivationStatus.None) + { + string status = searchModel.ContractingPartyStatus switch + { + ActivationStatus.Active => "true", + ActivationStatus.DeActive => "false", + _ => "" + }; + personalContractingPartiesQuery = personalContractingPartiesQuery + .Where(x => x.IsActiveString == status); + } + + + if (!string.IsNullOrWhiteSpace(searchModel.RepresentativeName)) + { + personalContractingPartiesQuery = personalContractingPartiesQuery + .Where(x => x.Representative.FullName.Contains(searchModel.RepresentativeName)); + } + + if (!string.IsNullOrWhiteSpace(searchModel.FullNameOrCompanyName)) + { + personalContractingPartiesQuery = personalContractingPartiesQuery.Where(x => + (x.FName + " " + x.LName).Contains(searchModel.FullNameOrCompanyName)); + } + var joinedQuery = personalContractingPartiesQuery + .GroupJoin(_context.InstitutionContractSet.Where(x => personalContractingPartiesQuery.Any(p => p.id == x.ContractingPartyId)), + contractingParty => contractingParty.id, + institution => institution.ContractingPartyId, + (contractingParty, institution) => new + { + contractingParty, + institution + }); + + var result = await joinedQuery.Skip(searchModel.PageIndex) + .Take(30).Select(x => new ContractingPartyGetListViewModel() + { + ArchiveCode = x.contractingParty.ArchiveCode, + BlockTimes = x.contractingParty.BlockTimes, + + ContractingPartyName = x.contractingParty.IsLegal == "حقیقی" ? + x.contractingParty.SureName == null ? $"{x.contractingParty.FName} {x.contractingParty.LName}" + : $"{x.contractingParty.FName} {x.contractingParty.LName} {x.contractingParty.SureName}" + : x.contractingParty.SureName == null ? $"{x.contractingParty.LName}" + : $"{x.contractingParty.LName} {x.contractingParty.SureName}", + + ContractingPartyType = x.contractingParty.IsLegal == "حقیقی" ? LegalType.Real : LegalType.Legal, + Employers = x.contractingParty.Employers.Take(11).Select(e => new ContractingPartyGetListEmployerViewModel(e.id, e.FullName)).ToList(), + Id = x.contractingParty.id, + IsBlock = x.contractingParty.IsBlock == "true", + HasInstitutionContract = x.institution.Any(i => i.IsActiveString == "true"), + NationalIdOrNationalCode = x.contractingParty.IsLegal == "حقیقی" ? x.contractingParty.Nationalcode : x.contractingParty.NationalId, + Status = x.contractingParty.IsActiveString == "true" ? ActivationStatus.Active : ActivationStatus.DeActive + }).ToListAsync(); + return result; + } + + public async Task> GetSelectList() + { + return await _context.PersonalContractingParties.Select(x => new ContractingPartySelectListViewModel + { + Id = x.id, + Text = x.IsLegal == "حقیقی" ? x.SureName == null + ? $"{x.FName} {x.LName}" + : $"{x.FName} {x.LName} {x.SureName}" + : x.SureName == null ? $"{x.LName}" + : $"{x.LName} {x.SureName}", + + }).ToListAsync(); + } + + public async Task> GetNationalCodeOrNationalId() + { + return await _context.PersonalContractingParties.Select(x => new GetContractingPartyNationalCodeOrNationalIdViewModel + { + NationalCodeOrNationalId = x.IsLegal == "true" ? x.NationalId : x.Nationalcode + }).ToListAsync(); + } + + public async Task> DeactivateWithSubordinates(long id) + { + var op = new OperationResult(); + ; + using (var transaction = await _context.Database.BeginTransactionAsync()) + { + try + { + var contractingParty = await _context.PersonalContractingParties + .Include(x => x.Employers) + .ThenInclude(x => x.Contracts) + .Include(x => x.Employers) + .ThenInclude(x => x.WorkshopEmployers) + .ThenInclude(x => x.Workshop) + .ThenInclude(x => x.Checkouts).FirstOrDefaultAsync(x => x.id == id); + if (contractingParty == null) + { + return op.Failed("چنین آیتمی وجود ندارد"); + } + + var employers = contractingParty.Employers; + + var workshops = employers.SelectMany(x => x.WorkshopEmployers).Select(x => x.Workshop).ToList(); + + var contracts = employers.SelectMany(x => x.Contracts).ToList(); + + var checkouts = workshops.SelectMany(x => x.Checkouts).ToList(); + + + contractingParty.DeActive(); + + foreach (var employer in employers) + { + 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("غیرفعال کردن طرف حساب با خطا مواجه شد"); + } + } + } + + public async Task GetRealDetails(long id) + { + var res = await _context.PersonalContractingParties.Where(x => x.IsLegal == "حقیقی").Select(x => + new GetRealContractingPartyDetailsViewModel() + { + Id = x.id, + IdNumber = x.IdNumber, + PhoneNumber = x.Phone, + AgentPhone = x.AgentPhone, + Address = x.Address, + FullName = x.SureName == null + ? $"{x.FName} {x.LName}" + : $"{x.FName} {x.LName} {x.SureName}", + NationalCode = x.Nationalcode, + RepresentativeName = x.RepresentativeFullName, + ArchiveCode = x.ArchiveCode, + City = x.City, + FName = x.FName, + LName = x.LName, + SureName = x.SureName, + RepresentativeId = x.RepresentativeId, + State = x.State, + Zone = x.Zone + }).FirstOrDefaultAsync(x => x.Id == id); + + if (res == null) + { + throw new BadRequestException("چنین طرف حسابی وجود ندارد"); + } + + return res; + } + + public async Task GetLegalDetails(long id) + { + var res = await _context.PersonalContractingParties.Where(x => x.IsLegal == "حقوقی").Select(x => + new GetLegalContractingPartyDetailsViewModel() + { + Id = x.id, + PhoneNumber = x.Phone, + AgentPhone = x.AgentPhone, + Address = x.Address, + CompanyFullName = x.SureName == null + ? $"{x.LName}" + : $"{x.LName} {x.SureName}", + NationalId = x.NationalId, + RegisterId = x.RegisterId, + RepresentativeName = x.RepresentativeFullName, + RepresentativeId = x.RepresentativeId, + State = x.State, + SureName = x.SureName, + Zone = x.Zone, + ArchiveCode = x.ArchiveCode, + City = x.City, + CompanyName = x.LName + }).FirstOrDefaultAsync(x => x.Id == id); + + if (res == null) + { + throw new BadRequestException("چنین طرف حسابی وجود ندارد"); + } + + return res; + } + + #endregion + } #endregion diff --git a/ServiceHost/Areas/Admin/Controllers/ContractingPartyController.cs b/ServiceHost/Areas/Admin/Controllers/ContractingPartyController.cs new file mode 100644 index 00000000..6202c7d6 --- /dev/null +++ b/ServiceHost/Areas/Admin/Controllers/ContractingPartyController.cs @@ -0,0 +1,173 @@ +using System.Diagnostics; +using _0_Framework.Application; +using CompanyManagment.App.Contracts.PersonalContractingParty; +using Microsoft.AspNetCore.Mvc; +using ServiceHost.BaseControllers; + +namespace ServiceHost.Areas.Admin.Controllers; + +public class ContractingPartyController : AdminController +{ + private readonly IPersonalContractingPartyApp _contractingPartyApplication; + + public ContractingPartyController(IPersonalContractingPartyApp contractingPartyApplication) + { + _contractingPartyApplication = contractingPartyApplication; + } + + /// + /// لیست طرف حساب + /// + /// + /// + [HttpGet] + public async Task>> Get([FromQuery] ContractingPartyGetListSearchModel searchModel) + { + var watch = new Stopwatch(); + watch.Start(); + var result = await _contractingPartyApplication.GetList(searchModel); + Console.WriteLine(watch.Elapsed); + return result.ToList(); + } + [HttpGet("t/{name}")] + public async Task> TestApi(string name) + { + var res = _contractingPartyApplication.SearchByName(name).Where(x=>x.Contains(name)).ToList(); + return res; + } + + /// + /// جزئیات طرف حساب حقیقی + /// + /// + /// + [HttpGet("real/{id}")] + public async Task> GetDetailsReal(long id) + { + var result = await _contractingPartyApplication.GetRealDetails(id); + return result; + } + + /// + /// جزئیات طرف حساب حقوقی + /// + /// + /// + [HttpGet("legal/{id}")] + public async Task> GetDetailsLegal(long id) + { + var result = await _contractingPartyApplication.GetLegalDetails(id); + return result; + + } + + + + + /// + /// ایجاد طرف حساب حقیقی + /// + /// + /// + [HttpPost("real")] + public async Task> CreateReal([FromBody] CreateRealContractingParty command) + { + var result = await _contractingPartyApplication.CreateReal(command); + return result; + } + + /// + /// ایجاد طرف حساب حقوقی + /// + /// + /// + [HttpPost("legal")] + public async Task> CreateLegal([FromBody] CreateLegalContractingParty command) + { + var result = await _contractingPartyApplication.CreateLegal(command); + return result; + } + + /// + /// ویرایش طرف حساب حقیقی + /// + /// + /// + [HttpPut("real")] + public ActionResult EditReal([FromBody] EditRealContractingParty command) + { + var result = _contractingPartyApplication.EditRealApi(command); + return result; + } + + /// + /// ویرایش طرف حساب حقوقی + /// + /// + /// + [HttpPut("legal")] + public ActionResult EditLegal([FromBody] EditLegalContractingParty command) + { + var result = _contractingPartyApplication.EditLegal(command); + return result; + } + + /// + /// چک کردن بلاک بودن طرف حساب با آیدی کارفرما + /// + /// آیدی کارفرما + /// true - false - NotFound + [HttpGet("is_block/{employerId}")] + public ActionResult IsBlockByEmployerId(long employerId) + { + var result = _contractingPartyApplication.IsBlockByEmployerId(employerId); + return result; + } + + /// + /// گرفتن آخرین کد بایگانی کارگاه + /// + /// + [HttpGet("last_archive_code")] + public ActionResult GetLastArchiveCodeByContractingPartyId() + { + var data = _contractingPartyApplication.GetLastArchiveCode(); + return data; + } + + /// + /// سلکت لیست طرف حساب برای جستجو + /// + /// + [HttpGet("selectList")] + public async Task>> GetSelectList() + { + return await _contractingPartyApplication.GetSelectList(); + } + + /// + /// لیست شناسه ملی یا شماره ملی برای جستجوی + /// + /// + [HttpGet("national_Code_Select_list")] + public async Task>> GetNationalCodeOrNationalId() + { + return await _contractingPartyApplication.GetNationalCodeOrNationalId(); + } + + /// + /// حذف طرف حساب. درصورت داشتن قرارداد مالی یا داشتن کارفرما، طرف حساب غیرفعال میشود + /// + /// + /// + [HttpDelete] + public async Task> DeleteContractingParty(long id) + { + var operationResult = await _contractingPartyApplication.Delete(id); + + return operationResult; + } + + + +} \ No newline at end of file diff --git a/ServiceHost/BaseControllers/AdminController.cs b/ServiceHost/BaseControllers/AdminController.cs new file mode 100644 index 00000000..b9e9c2ff --- /dev/null +++ b/ServiceHost/BaseControllers/AdminController.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +namespace ServiceHost.BaseControllers; + +//[Authorize(Policy = "AdminArea")] +[Area("Admin")] +[ApiExplorerSettings(GroupName = "Admin")] +[Route("api/[area]/[controller]")] +public class AdminController:ControllerBase +{ + +} \ No newline at end of file diff --git a/ServiceHost/Program.cs b/ServiceHost/Program.cs index d2dada1e..4ac2a728 100644 --- a/ServiceHost/Program.cs +++ b/ServiceHost/Program.cs @@ -127,6 +127,12 @@ builder.Services.AddAuthorization(options => // }); +builder.Services.AddControllers() + .AddJsonOptions(options => + { + options.JsonSerializerOptions.Converters.Add(new System.Text.Json.Serialization.JsonStringEnumConverter()); + }); + builder.Services.AddRazorPages(options => options.Conventions.AuthorizeAreaFolder("Admin", "/", "AdminArea"));