From d1ac8e49baa6d77817e521eea107d563138df8cc Mon Sep 17 00:00:00 2001 From: mahan Date: Sat, 1 Nov 2025 12:15:35 +0330 Subject: [PATCH] feat: add API endpoint to retrieve working employees select list for current workshop --- .../EmployeeAgg/IEmployeeRepository.cs | 1 + .../Employee/IEmployeeApplication.cs | 1 + .../EmployeeAplication.cs | 4 +++ .../Repository/EmployeeRepository .cs | 26 ++++++++++++++++++- .../Client/Controllers/RollCallController.cs | 12 ++++++++- 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/Company.Domain/EmployeeAgg/IEmployeeRepository.cs b/Company.Domain/EmployeeAgg/IEmployeeRepository.cs index 43a2564a..e6238ac3 100644 --- a/Company.Domain/EmployeeAgg/IEmployeeRepository.cs +++ b/Company.Domain/EmployeeAgg/IEmployeeRepository.cs @@ -79,4 +79,5 @@ public interface IEmployeeRepository : IRepository #endregion + Task> GetWorkingEmployeesSelectList(long workshopId); } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Employee/IEmployeeApplication.cs b/CompanyManagment.App.Contracts/Employee/IEmployeeApplication.cs index 2f1b692d..89e15168 100644 --- a/CompanyManagment.App.Contracts/Employee/IEmployeeApplication.cs +++ b/CompanyManagment.App.Contracts/Employee/IEmployeeApplication.cs @@ -76,6 +76,7 @@ public interface IEmployeeApplication Task> WorkedEmployeesInWorkshopSelectList(long workshopId); Task> GetEmployeeDataFromApi(string nationalCode, string birthDate); + Task> GetWorkingEmployeesSelectList(long workshopId); #endregion diff --git a/CompanyManagment.Application/EmployeeAplication.cs b/CompanyManagment.Application/EmployeeAplication.cs index 47624e1f..353a7d74 100644 --- a/CompanyManagment.Application/EmployeeAplication.cs +++ b/CompanyManagment.Application/EmployeeAplication.cs @@ -1676,6 +1676,10 @@ public class EmployeeAplication : RepositoryBase, IEmployeeAppli } + public async Task> GetWorkingEmployeesSelectList(long workshopId) + { + return await _EmployeeRepository.GetWorkingEmployeesSelectList(workshopId); + } #endregion diff --git a/CompanyManagment.EFCore/Repository/EmployeeRepository .cs b/CompanyManagment.EFCore/Repository/EmployeeRepository .cs index bd02e8fa..108c184a 100644 --- a/CompanyManagment.EFCore/Repository/EmployeeRepository .cs +++ b/CompanyManagment.EFCore/Repository/EmployeeRepository .cs @@ -1062,5 +1062,29 @@ public class EmployeeRepository : RepositoryBase, IEmployeeRepos } - #endregion + public async Task> GetWorkingEmployeesSelectList(long workshopId) + { + var dateNow = DateTime.Now.Date; + + + var workshopActiveLeftWorksQuery = _context.LeftWorkList.Where(x => x.WorkshopId == workshopId && + x.StartWorkDate <= dateNow && x.LeftWorkDate > dateNow); + + + var workshopActiveInsuranceLeftWorksQuery = _context.LeftWorkInsuranceList.Where(x => x.WorkshopId == workshopId && + x.StartWorkDate <= dateNow && (x.LeftWorkDate > dateNow || x.LeftWorkDate == null)); + + + var employeesQuery = _context.Employees.Where(x => workshopActiveLeftWorksQuery.Any(y => y.EmployeeId == x.id) || + workshopActiveInsuranceLeftWorksQuery.Any(y => y.EmployeeId == x.id)); + + + return await employeesQuery.Select(x => new EmployeeSelectListViewModel() + { + Id = x.id, + EmployeeFullName = x.FullName + }).ToListAsync(); + } + + #endregion } \ No newline at end of file diff --git a/ServiceHost/Areas/Client/Controllers/RollCallController.cs b/ServiceHost/Areas/Client/Controllers/RollCallController.cs index 83806e3f..25585f20 100644 --- a/ServiceHost/Areas/Client/Controllers/RollCallController.cs +++ b/ServiceHost/Areas/Client/Controllers/RollCallController.cs @@ -1,5 +1,6 @@ using _0_Framework.Application; using Company.Domain.CheckoutAgg; +using CompanyManagment.App.Contracts.Employee; using CompanyManagment.App.Contracts.RollCall; using Microsoft.AspNetCore.Mvc; using ServiceHost.BaseControllers; @@ -10,10 +11,12 @@ public class RollCallController:ClientBaseController { private long _workshopId; private readonly IRollCallApplication _rollCallApplication; + private readonly IEmployeeApplication _employeeApplication; - public RollCallController(IRollCallApplication rollCallApplication,IAuthHelper authHelper) + public RollCallController(IRollCallApplication rollCallApplication,IAuthHelper authHelper, IEmployeeApplication employeeApplication) { _rollCallApplication = rollCallApplication; + _employeeApplication = employeeApplication; _workshopId = authHelper.GetWorkshopId(); } [HttpGet("current-day")] @@ -22,4 +25,11 @@ public class RollCallController:ClientBaseController var res = _rollCallApplication.GetWorkshopCurrentDayRollCalls(_workshopId, searchModel); return res; } + + [HttpGet("employee-select-list")] + public async Task>> GetEmployeeSelectList() + { + var res = await _employeeApplication.GetWorkingEmployeesSelectList(_workshopId); + return res; + } } \ No newline at end of file