using System.Globalization; using CompanyManagment.EFCore; using Microsoft.EntityFrameworkCore; using Query.ClientReports.Models; namespace Query.ClientReports.Handler { public class NotSignedContractEmployeesQueryHandler { private readonly CompanyContext _companyContext; public NotSignedContractEmployeesQueryHandler(CompanyContext companyContext) { _companyContext = companyContext; } public List Handle(long workshopId, int yearFa, int monthFa) { var date = new DateTime(yearFa, monthFa, 1, new PersianCalendar()); int nextMonth; int nextMonthYear; if (monthFa == 12) { nextMonthYear = yearFa + 1; nextMonth = 1; } else { nextMonth = monthFa + 1; nextMonthYear = yearFa; } var nextMonthDate = new DateTime(nextMonthYear, nextMonth, 1, new PersianCalendar()); var query = _companyContext.Employees.Include(x => x.Contracts).Where(x => !x.Contracts.Any(y => y.ContarctStart < nextMonthDate && y.ContractEnd >= date && y.Signature == "0")); return query.Select(x => new NotSignedContractEmployeesQueryModel() { MonthFa = monthFa, YearFa = yearFa, EmployeeFullName = x.FName + " " + x.LName, EmployeeId = x.id }).ToList(); } } }