From 3f2c0c5531eab9eb38e1e778ace6eba5fe023f17 Mon Sep 17 00:00:00 2001 From: MahanCh Date: Tue, 27 May 2025 18:06:28 +0330 Subject: [PATCH] fix subAccount Workshop Personnel Count --- .../AccountApplication.cs | 2 +- .../Workshop/WorkshopSubAccountViewModel.cs | 1 + .../WorkshopSubAccountRepository.cs | 27 ++++++++++++++----- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/AccountManagement.Application/AccountApplication.cs b/AccountManagement.Application/AccountApplication.cs index eae5c9e1..7c32b7db 100644 --- a/AccountManagement.Application/AccountApplication.cs +++ b/AccountManagement.Application/AccountApplication.cs @@ -308,7 +308,7 @@ public class AccountApplication : IAccountApplication { Slug = _passwordHasher.SlugHasher(x.WorkshopId), Name = x.WorkshopName, - PersonnelCount = 0, + PersonnelCount = x.PersonnelCount, Id = x.WorkshopId }).ToList(); diff --git a/CompanyManagment.App.Contracts/Workshop/WorkshopSubAccountViewModel.cs b/CompanyManagment.App.Contracts/Workshop/WorkshopSubAccountViewModel.cs index 3e5fd6ca..beca089e 100644 --- a/CompanyManagment.App.Contracts/Workshop/WorkshopSubAccountViewModel.cs +++ b/CompanyManagment.App.Contracts/Workshop/WorkshopSubAccountViewModel.cs @@ -7,5 +7,6 @@ namespace CompanyManagment.App.Contracts.Workshop public string WorkshopName { get; set; } public long SubAccountId { get; set; } public string IsActive { get; set; } + public int PersonnelCount { get; set; } } } diff --git a/CompanyManagment.EFCore/Repository/WorkshopSubAccountRepository.cs b/CompanyManagment.EFCore/Repository/WorkshopSubAccountRepository.cs index 94d44800..65994163 100644 --- a/CompanyManagment.EFCore/Repository/WorkshopSubAccountRepository.cs +++ b/CompanyManagment.EFCore/Repository/WorkshopSubAccountRepository.cs @@ -1,9 +1,12 @@ -using _0_Framework.InfraStructure; +using System; +using _0_Framework.InfraStructure; using Company.Domain.WorkshopSubAccountAgg; using CompanyManagment.App.Contracts.Workshop; using Microsoft.EntityFrameworkCore; using System.Collections.Generic; +using System.Data; using System.Linq; +using AccountManagement.Domain.SubAccountAgg; namespace CompanyManagment.EFCore.Repository; @@ -17,15 +20,25 @@ public class WorkshopSubAccountRepository : RepositoryBase GetWorkshopsBySubAccountId(long subAccountId) { - return _companyContext.WorkshopSubAccounts.Include(x => x.Workshop).Where(x => x.SubAccountId == subAccountId) - .Select(x => new WorkshopSubAccountViewModel() + var dateNow = DateTime.Today; + + var viewModelList = _companyContext.WorkshopSubAccounts + .Include(x => x.Workshop) + .Where(x => x.SubAccountId == subAccountId) + .Select(sub => new WorkshopSubAccountViewModel { - SubAccountId = x.SubAccountId, - IsActive = x.IsActive.ToString(), - WorkshopId = x.WorkshopId, - WorkshopName = x.Workshop.WorkshopName, + SubAccountId = sub.SubAccountId, + IsActive = sub.IsActive.ToString(), + WorkshopId = sub.WorkshopId, + WorkshopName = sub.Workshop.WorkshopName, + PersonnelCount = _companyContext.LeftWorkList.Count(left => + left.WorkshopId == sub.WorkshopId && + left.StartWorkDate <= dateNow && + left.LeftWorkDate > dateNow) }) .ToList(); + + return viewModelList; } public List GetWorkshopsSubAccountEntityBySubAccountId(long subAccountId)