Added a filter of only date while fetching data from database

This commit is contained in:
ashutosh.nehete 2025-04-11 16:42:51 +05:30
parent 38262074c4
commit 52d0474d45

View File

@ -17,13 +17,13 @@ namespace Marco.Pms.Services.Controllers
{ {
private readonly ApplicationDbContext _context; private readonly ApplicationDbContext _context;
private readonly UserHelper _userHelper; private readonly UserHelper _userHelper;
public DashboardController(ApplicationDbContext context,UserHelper userHelper) public DashboardController(ApplicationDbContext context, UserHelper userHelper)
{ {
_context = context; _context = context;
_userHelper = userHelper; _userHelper = userHelper;
} }
[HttpGet("progression")] [HttpGet("progression")]
public async Task<IActionResult> GetGraph([FromQuery] double days,[FromQuery] int projectId, [FromQuery] string? FromDate) public async Task<IActionResult> GetGraph([FromQuery] double days, [FromQuery] int projectId, [FromQuery] string? FromDate)
{ {
var tenantId = _userHelper.GetTenantId(); var tenantId = _userHelper.GetTenantId();
DateTime fromDate = new DateTime(); DateTime fromDate = new DateTime();
@ -34,7 +34,7 @@ namespace Marco.Pms.Services.Controllers
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid starting date.", "Invalid starting date.", 400)); return BadRequest(ApiResponse<object>.ErrorResponse("Invalid starting date.", "Invalid starting date.", 400));
} }
if(projectId == null) { projectId = 0; } if (projectId == null) { projectId = 0; }
if (FromDate == null) fromDate = DateTime.UtcNow.Date; if (FromDate == null) fromDate = DateTime.UtcNow.Date;
@ -44,8 +44,8 @@ namespace Marco.Pms.Services.Controllers
toDate = fromDate.AddDays(negativeDays); toDate = fromDate.AddDays(negativeDays);
if (projectId == 0) if (projectId == 0)
{ {
List<TaskAllocation> tasks = await _context.TaskAllocations.Where(t => t.AssignmentDate <= fromDate && t.AssignmentDate >= toDate && t.TenantId == tenantId).ToListAsync(); List<TaskAllocation> tasks = await _context.TaskAllocations.Where(t => t.AssignmentDate.Date <= fromDate.Date && t.AssignmentDate.Date >= toDate.Date && t.TenantId == tenantId).ToListAsync();
double flagDays = 0; double flagDays = 0;
while (negativeDays < flagDays) while (negativeDays < flagDays)
{ {
@ -85,8 +85,8 @@ namespace Marco.Pms.Services.Controllers
List<WorkItem> workItems = await _context.WorkItems.Where(i => idList.Contains(i.WorkAreaId) && i.TenantId == tenantId).ToListAsync(); List<WorkItem> workItems = await _context.WorkItems.Where(i => idList.Contains(i.WorkAreaId) && i.TenantId == tenantId).ToListAsync();
idList = workItems.Select(i => i.Id).ToList(); idList = workItems.Select(i => i.Id).ToList();
List<TaskAllocation> tasks = await _context.TaskAllocations.Where(t => idList.Contains(t.WorkItemId) && t.AssignmentDate <= fromDate && t.AssignmentDate >= toDate && t.TenantId == tenantId).ToListAsync(); List<TaskAllocation> tasks = await _context.TaskAllocations.Where(t => idList.Contains(t.WorkItemId) && t.AssignmentDate.Date <= fromDate.Date && t.AssignmentDate.Date >= toDate.Date && t.TenantId == tenantId).ToListAsync();
if(project != null) if (project != null)
{ {
double flagDays = 0; double flagDays = 0;
while (negativeDays < flagDays) while (negativeDays < flagDays)
@ -142,7 +142,7 @@ namespace Marco.Pms.Services.Controllers
var Employees = await _context.Employees.Where(e => e.TenantId == tenantId && e.IsActive == true).Select(e => e.Id).ToListAsync(); var Employees = await _context.Employees.Where(e => e.TenantId == tenantId && e.IsActive == true).Select(e => e.Id).ToListAsync();
var checkedInEmployee = await _context.Attendes.Where(e => e.Date.Date == date ).ToListAsync(); var checkedInEmployee = await _context.Attendes.Where(e => e.Date.Date == date).ToListAsync();
TeamDashboardVM teamDashboardVM = new TeamDashboardVM TeamDashboardVM teamDashboardVM = new TeamDashboardVM
{ {
@ -157,7 +157,7 @@ namespace Marco.Pms.Services.Controllers
{ {
var tenantId = _userHelper.GetTenantId(); var tenantId = _userHelper.GetTenantId();
var Tasks = await _context.WorkItems.Where(t => t.TenantId == tenantId).Select(t => new { PlannedWork = t.PlannedWork, CompletedWork = t.CompletedWork}).ToListAsync(); var Tasks = await _context.WorkItems.Where(t => t.TenantId == tenantId).Select(t => new { PlannedWork = t.PlannedWork, CompletedWork = t.CompletedWork }).ToListAsync();
TasksDashboardVM tasksDashboardVM = new TasksDashboardVM TasksDashboardVM tasksDashboardVM = new TasksDashboardVM
{ {
TotalTasks = 0, TotalTasks = 0,