From 16b85676a25ed9e7759dbe77f776e52094f26ad4 Mon Sep 17 00:00:00 2001 From: SamSys Date: Mon, 13 Jan 2025 20:10:25 +0330 Subject: [PATCH] added new metod for getting workshop on client login --- .../AccountApplication.cs | 16 +++++----- .../WorkshopAgg/IWorkshopRepository.cs | 1 + .../Repository/WorkshopRepository.cs | 30 ++++++++++++++++++- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/AccountManagement.Application/AccountApplication.cs b/AccountManagement.Application/AccountApplication.cs index 14c4d5bd..e8cf0446 100644 --- a/AccountManagement.Application/AccountApplication.cs +++ b/AccountManagement.Application/AccountApplication.cs @@ -246,15 +246,13 @@ public class AccountApplication : IAccountApplication { var clientPermissions = _accountPermissionSubtitle1Repository.GetAllPermissionCodes(); authViewModel.Permissions = clientPermissions; - var workshopList = _workshopRepository.SearchForClient(new WorkshopSearchModel() { AccountId = account.id }) - .OrderByDescending(x => x.PersonnelCount).ToList().Select(x => new WorkshopClaim() - { - Slug = _passwordHasher.SlugHasher(x.Id), - Name = x.WorkshopFullName, - PersonnelCount = x.PersonnelCount, - Id = x.Id - } - ).ToList(); + var workshopList = _workshopRepository.GetWorkshopsByClientAccountId(account.id).Select(x => new WorkshopClaim + { + PersonnelCount = x.PersonnelCount, + Id = x.Id, + Name = x.WorkshopFullName, + Slug = _passwordHasher.SlugHasher(x.Id) + }).OrderByDescending(x => x.PersonnelCount).ToList(); authViewModel.WorkshopList = workshopList; if (workshopList.Any()) authViewModel.WorkshopSlug = _passwordHasher.SlugHasher(workshopList.First().Id); diff --git a/Company.Domain/WorkshopAgg/IWorkshopRepository.cs b/Company.Domain/WorkshopAgg/IWorkshopRepository.cs index b3cf1731..14612d9d 100644 --- a/Company.Domain/WorkshopAgg/IWorkshopRepository.cs +++ b/Company.Domain/WorkshopAgg/IWorkshopRepository.cs @@ -61,6 +61,7 @@ public interface IWorkshopRepository : IRepository #endregion #region Mahan PersonalContractingPartyViewModel GetPersonalContractingPartyByWorkshopId(long workshopId); + List GetWorkshopsByClientAccountId(long clientAccountId); #endregion } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/WorkshopRepository.cs b/CompanyManagment.EFCore/Repository/WorkshopRepository.cs index ecd11ece..bdf6910c 100644 --- a/CompanyManagment.EFCore/Repository/WorkshopRepository.cs +++ b/CompanyManagment.EFCore/Repository/WorkshopRepository.cs @@ -6,6 +6,8 @@ using _0_Framework.Application; using _0_Framework.InfraStructure; using AccountManagement.Application.Contracts.Account; using AccountMangement.Infrastructure.EFCore; +using Company.Domain.EmployeeAgg; +using Company.Domain.empolyerAgg; using Company.Domain.WorkshopAccountAgg; using Company.Domain.WorkshopAgg; using Company.Domain.WorkshopEmployerAgg; @@ -27,13 +29,15 @@ public class WorkshopRepository : RepositoryBase GetWorkshopsByClientAccountId(long clientAccountId) + { + var workshops = _context.ContractingPartyAccounts.Where(x => x.AccountId == clientAccountId) + .Include(x => x.PersonalContractingParty) + .ThenInclude(x => x.Employers).ThenInclude(x => x.WorkshopEmployers).ThenInclude(x => x.Workshop).SelectMany(x => + x.PersonalContractingParty.Employers.SelectMany(e => e.WorkshopEmployers).Select(e => e.Workshop)).Distinct().Select(x => new WorkshopViewModel() + { + Id = x.id, + WorkshopFullName = x.WorkshopFullName, + }).ToList(); + + workshops = workshops.Select(x => new WorkshopViewModel() + { + Id = x.Id, + WorkshopFullName = x.WorkshopFullName, + PersonnelCount = _employeeRepository.GetWorkingEmployeesByWorkshopId(x.Id).Count(), + }).ToList(); + + + return workshops; + + + } + #endregion #region NewByHeydari