diff --git a/Company.Domain/ContarctingPartyAgg/IPersonalContractingPartyRepository.cs b/Company.Domain/ContarctingPartyAgg/IPersonalContractingPartyRepository.cs index 17e588a8..2012a3b1 100644 --- a/Company.Domain/ContarctingPartyAgg/IPersonalContractingPartyRepository.cs +++ b/Company.Domain/ContarctingPartyAgg/IPersonalContractingPartyRepository.cs @@ -53,8 +53,9 @@ public interface IPersonalContractingPartyRepository :IRepository /// لیست طرف حساب برای سلکت لیست سرچ /// + /// /// - Task> GetSelectList(); + Task> GetSelectList(string search); /// /// لیستی از شماره ملی یا شناسه ملی بر اساس حقیقی یا حقوقی بودن diff --git a/CompanyManagment.App.Contracts/PersonalContractingParty/IPersonalContractingPartyApp.cs b/CompanyManagment.App.Contracts/PersonalContractingParty/IPersonalContractingPartyApp.cs index cfa0bc11..d672910e 100644 --- a/CompanyManagment.App.Contracts/PersonalContractingParty/IPersonalContractingPartyApp.cs +++ b/CompanyManagment.App.Contracts/PersonalContractingParty/IPersonalContractingPartyApp.cs @@ -67,8 +67,9 @@ public interface IPersonalContractingPartyApp /// /// لیست طرف حساب برای سلکت لیست سرچ /// + /// /// - Task> GetSelectList(); + Task> GetSelectList(string search); /// /// ایجاد طرف حساب حقیقی diff --git a/CompanyManagment.Application/PersonalContractingPartyApplication.cs b/CompanyManagment.Application/PersonalContractingPartyApplication.cs index d44162ff..9a69f1ce 100644 --- a/CompanyManagment.Application/PersonalContractingPartyApplication.cs +++ b/CompanyManagment.Application/PersonalContractingPartyApplication.cs @@ -518,9 +518,9 @@ public class PersonalContractingPartyApplication : IPersonalContractingPartyApp return await _personalContractingPartyRepository.GetList(searchModel); } - public async Task> GetSelectList() + public async Task> GetSelectList(string search) { - return await _personalContractingPartyRepository.GetSelectList(); + return await _personalContractingPartyRepository.GetSelectList(search); } public async Task CreateReal(CreateRealContractingParty command) { diff --git a/CompanyManagment.EFCore/Repository/PersonalContractingPartyRepository.cs b/CompanyManagment.EFCore/Repository/PersonalContractingPartyRepository.cs index abf99bab..d1a03baf 100644 --- a/CompanyManagment.EFCore/Repository/PersonalContractingPartyRepository.cs +++ b/CompanyManagment.EFCore/Repository/PersonalContractingPartyRepository.cs @@ -41,7 +41,7 @@ public class PersonalContractingPartyRepository : RepositoryBase new PersonalContractingPartyViewModel() @@ -51,7 +51,7 @@ public class PersonalContractingPartyRepository : RepositoryBase new EditPersonalContractingParty() - { - Id = x.id, - - FName = x.FName, - LName = x.IsLegal == "حقیقی" ? $"{x.FName} {x.LName}" : $"{x.LName}", - SureName = x.SureName, - Nationalcode = x.Nationalcode, - IdNumber = x.IdNumber, - RegisterId = x.RegisterId, - NationalId = x.NationalId, - IsLegal = x.IsLegal, - Phone = x.Phone, - AgentPhone = x.AgentPhone, - Address = x.Address, - ArchiveCode = x.ArchiveCode, - RepresentativeId = x.RepresentativeId, - RepresentativeFullName = x.RepresentativeFullName, - State = x.State, - City = x.City, - Zone = x.Zone, - IsActiveString = x.IsActiveString, - IsBlock = x.IsBlock, - BlockTimes = x.BlockTimes, + { + Id = x.id, + + FName = x.FName, + LName = x.IsLegal == "حقیقی" ? $"{x.FName} {x.LName}" : $"{x.LName}", + SureName = x.SureName, + Nationalcode = x.Nationalcode, + IdNumber = x.IdNumber, + RegisterId = x.RegisterId, + NationalId = x.NationalId, + IsLegal = x.IsLegal, + Phone = x.Phone, + AgentPhone = x.AgentPhone, + Address = x.Address, + ArchiveCode = x.ArchiveCode, + RepresentativeId = x.RepresentativeId, + RepresentativeFullName = x.RepresentativeFullName, + State = x.State, + City = x.City, + Zone = x.Zone, + IsActiveString = x.IsActiveString, + IsBlock = x.IsBlock, + BlockTimes = x.BlockTimes, - }) + }) .FirstOrDefault(x => x.Id == id); if (res != null) @@ -112,32 +112,32 @@ public class PersonalContractingPartyRepository : RepositoryBase new EditPersonalContractingParty() - { - Id = x.id, + { + Id = x.id, - FName = x.FName, - LName = x.LName, - SureName = x.SureName, - Nationalcode = x.Nationalcode, - IdNumber = x.IdNumber, - RegisterId = x.RegisterId, - NationalId = x.NationalId, - IsLegal = x.IsLegal, - Phone = x.Phone, - AgentPhone = x.AgentPhone, - Address = x.Address, - ArchiveCode = x.ArchiveCode, - RepresentativeId = x.RepresentativeId, - RepresentativeFullName = x.RepresentativeFullName, - State = x.State, - City = x.City, - Zone = x.Zone, - IsActiveString = x.IsActiveString, - IsBlock = x.IsBlock, - BlockTimes = x.BlockTimes, + FName = x.FName, + LName = x.LName, + SureName = x.SureName, + Nationalcode = x.Nationalcode, + IdNumber = x.IdNumber, + RegisterId = x.RegisterId, + NationalId = x.NationalId, + IsLegal = x.IsLegal, + Phone = x.Phone, + AgentPhone = x.AgentPhone, + Address = x.Address, + ArchiveCode = x.ArchiveCode, + RepresentativeId = x.RepresentativeId, + RepresentativeFullName = x.RepresentativeFullName, + State = x.State, + City = x.City, + Zone = x.Zone, + IsActiveString = x.IsActiveString, + IsBlock = x.IsBlock, + BlockTimes = x.BlockTimes, - }) + }) .FirstOrDefault(x => x.Id == id); } @@ -154,7 +154,7 @@ public class PersonalContractingPartyRepository : RepositoryBase x.id == id); - + if (res != null) { @@ -167,8 +167,8 @@ public class PersonalContractingPartyRepository : RepositoryBase new PersonalContractingPartyViewModel { id = x.id, - + FName = x.FName, LName = !string.IsNullOrWhiteSpace(x.SureName) ? $"{x.LName} ({x.SureName})" : $"{x.LName}", SureName = x.SureName, @@ -224,7 +224,7 @@ public class PersonalContractingPartyRepository : RepositoryBase 0) { - + res += 1; return res; } @@ -237,13 +237,13 @@ public class PersonalContractingPartyRepository : RepositoryBase SearchByName(string name) - { - var contractingParties = _context.PersonalContractingParties.Select(x => new PersonalContractingPartyViewModel() - { - FullName = x.IsLegal == "حقوقی" ? x.LName : $"{x.FName} {x.LName}" - }).ToList(); - return contractingParties.Select(x => x.FullName).ToList(); - } + { + var contractingParties = _context.PersonalContractingParties.Select(x => new PersonalContractingPartyViewModel() + { + FullName = x.IsLegal == "حقوقی" ? x.LName : $"{x.FName} {x.LName}" + }).ToList(); + return contractingParties.Select(x => x.FullName).ToList(); + } public AccountViewModel GetAccountByPersonalContractingParty(long contractingPartyId) { @@ -268,7 +268,7 @@ public class PersonalContractingPartyRepository : RepositoryBase GetPersonalContractingPartiesForNationalcode(string searchText) { - var result = _context.PersonalContractingParties.Where(x => (!string.IsNullOrEmpty(x.Nationalcode) && x.Nationalcode.StartsWith(searchText)) ) + var result = _context.PersonalContractingParties.Where(x => (!string.IsNullOrEmpty(x.Nationalcode) && x.Nationalcode.StartsWith(searchText))) .Select(x => new PersonalContractingPartyViewModel { id = x.id, @@ -280,7 +280,7 @@ public class PersonalContractingPartyRepository : RepositoryBase SearchForMain(PersonalContractingPartySearchModel searchModel2) { - var query = _context.PersonalContractingParties.Include(x=>x.Employers).Select(x => new PersonalContractingPartyViewModel + var query = _context.PersonalContractingParties.Include(x => x.Employers).Select(x => new PersonalContractingPartyViewModel { id = x.id, @@ -293,7 +293,7 @@ public class PersonalContractingPartyRepository : RepositoryBase new EmployerViewModel() { Id = y.id, FullName = y.FullName}).ToList() + EmployerList = x.Employers.Select(y => new EmployerViewModel() { Id = y.id, FullName = y.FullName }).ToList() }); if (searchModel2.id > 0) query = query.Where(x => x.id == searchModel2.id); - + if (!string.IsNullOrWhiteSpace(searchModel2.Nationalcode) && searchModel2.Nationalcode != "0") query = query.Where(x => x.Nationalcode.Contains(searchModel2.Nationalcode)); if (searchModel2.RepresentativeId > 0) - query = query.Where(x => x.RepresentativeId== searchModel2.RepresentativeId); + query = query.Where(x => x.RepresentativeId == searchModel2.RepresentativeId); if (!string.IsNullOrWhiteSpace(searchModel2.IsLegal)) - query = query.Where(x => x.IsLegal==searchModel2.IsLegal); + query = query.Where(x => x.IsLegal == searchModel2.IsLegal); - if (!string.IsNullOrWhiteSpace(searchModel2.IsActiveString)&& searchModel2.IsActiveString!="both") - query = query.Where(x => x.IsActiveString==searchModel2.IsActiveString); + if (!string.IsNullOrWhiteSpace(searchModel2.IsActiveString) && searchModel2.IsActiveString != "both") + query = query.Where(x => x.IsActiveString == searchModel2.IsActiveString); if (!string.IsNullOrEmpty(searchModel2.RepresentativeName)) { - var representativeIds = _context.RepresentativeSet.Where(x => !string.IsNullOrEmpty(x.FullName) && x.FullName.Contains(searchModel2.RepresentativeName)).Select(x=>x.id).ToList(); - query = query.Where(x => representativeIds.Contains( x.RepresentativeId)); + var representativeIds = _context.RepresentativeSet.Where(x => !string.IsNullOrEmpty(x.FullName) && x.FullName.Contains(searchModel2.RepresentativeName)).Select(x => x.id).ToList(); + query = query.Where(x => representativeIds.Contains(x.RepresentativeId)); } if (!string.IsNullOrEmpty(searchModel2.EmployeeName)) { - query = query.Where(x => (x.IsLegal == "حقیقی" && + query = query.Where(x => (x.IsLegal == "حقیقی" && ((!string.IsNullOrWhiteSpace(x.FName) && x.FName.StartsWith(searchModel2.EmployeeName)) || (!string.IsNullOrWhiteSpace(x.LName) && x.LName.StartsWith(searchModel2.EmployeeName)))) || (x.IsLegal == "حقوقی" && (!string.IsNullOrWhiteSpace(x.LName) && x.LName.Contains(searchModel2.EmployeeName)))); @@ -351,10 +351,10 @@ public class PersonalContractingPartyRepository : RepositoryBasex.IsActiveString== "true" && x.ContractingPartyId == id); + return _context.InstitutionContractSet.Any(x => x.IsActiveString == "true" && x.ContractingPartyId == id); } public OperationResult DeActiveAll(long id) @@ -368,10 +368,10 @@ public class PersonalContractingPartyRepository : RepositoryBase x.ContractingPartyId == id).ToList(); - employers.ForEach(x=>x.DeActive()); + employers.ForEach(x => x.DeActive()); - var employerIds= employers.Select(x=>x.id).ToList(); - var workshopIds=_context.WorkshopEmployers.Where(x=> employerIds.Contains(x.EmployerId)).Select(x=>x.WorkshopId).ToList(); + var employerIds = employers.Select(x => x.id).ToList(); + var workshopIds = _context.WorkshopEmployers.Where(x => employerIds.Contains(x.EmployerId)).Select(x => x.WorkshopId).ToList(); var workshops = _context.Workshops.Where(x => workshopIds.Contains(x.id)).ToList(); workshops.ForEach(x => x.DeActive(x.ArchiveCode)); @@ -443,7 +443,7 @@ public class PersonalContractingPartyRepository : RepositoryBase x.id == emp.ContractingPartyId); if (res != null) return res.IsBlock; - + return $"NotFound"; } @@ -459,14 +459,14 @@ public class PersonalContractingPartyRepository : RepositoryBase x.ContractingParty) .Select(c => c.Employer.ContractingParty); return e.Any(x => x.IsBlock == "true"); - } + } #endregion #region ForClients public ContractingPartyAndStatmentIdViewModel GetContractingpartyIdByAccountId(long accountId) { - var contractingPartId = _context.ContractingPartyAccounts.Any(x => x.AccountId == accountId) ? + var contractingPartId = _context.ContractingPartyAccounts.Any(x => x.AccountId == accountId) ? _context.ContractingPartyAccounts.FirstOrDefault(x => x.AccountId == accountId)!.PersonalContractingPartyId : 0; var financialStatmentId = _context.FinancialStatments .Any(x => x.ContractingPartyId == contractingPartId) ? _context.FinancialStatments @@ -572,18 +572,24 @@ public class PersonalContractingPartyRepository : RepositoryBase> GetSelectList() + public async Task> GetSelectList(string search) { - return await _context.PersonalContractingParties.Select(x => new ContractingPartySelectListViewModel + var query = _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}", + ? x.FName + " " + x.LName + : x.FName + " " + x.LName + " " + x.SureName + : x.SureName == null ? x.LName + : x.LName + " " + x.SureName - }).ToListAsync(); + }); + if (!string.IsNullOrWhiteSpace(search)) + { + query = query.Where(x => x.Text.Contains(search)); + } + + return await query.Take(100).ToListAsync(); } public async Task> GetNationalCodeOrNationalId() diff --git a/ServiceHost/Areas/Admin/Controllers/ContractingPartyController.cs b/ServiceHost/Areas/Admin/Controllers/ContractingPartyController.cs index 3ddae363..fbce5aaf 100644 --- a/ServiceHost/Areas/Admin/Controllers/ContractingPartyController.cs +++ b/ServiceHost/Areas/Admin/Controllers/ContractingPartyController.cs @@ -140,9 +140,9 @@ public class ContractingPartyController : AdminBaseController /// /// [HttpGet("selectList")] - public async Task>> GetSelectList() + public async Task>> GetSelectList(string search) { - return await _contractingPartyApplication.GetSelectList(); + return await _contractingPartyApplication.GetSelectList(search); } ///