Created new view models for showing taskAllication list and comment

This commit is contained in:
ashutosh.nehete 2025-04-05 17:16:32 +05:30
parent 64c4772595
commit 745b4d2e1c
7 changed files with 97 additions and 33 deletions

View File

@ -1,8 +1,7 @@
using Marco.Pms.Model.Employees;
using Marco.Pms.Model.Entitlements;
using System.ComponentModel.DataAnnotations.Schema;
using Marco.Pms.Model.Employees;
using Marco.Pms.Model.Utilities;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using System.ComponentModel.DataAnnotations.Schema;
namespace Marco.Pms.Model.Activities
{

View File

@ -95,5 +95,33 @@ namespace Marco.Pms.Model.Mapper
TenantId = tenantId
};
}
public static ListTaskVM ToListTaskVMFromTaskAllocation(this TaskAllocation taskAllocation)
{
return new ListTaskVM
{
Id = taskAllocation.Id,
AssignmentDate = taskAllocation.AssignmentDate,
PlannedTask = taskAllocation.PlannedTask,
CompletedTask = taskAllocation.CompletedTask,
AssignedBy = taskAllocation.Employee.ToEmployeeVMFromEmployee(),
WorkItemId = taskAllocation.WorkItemId,
WorkItem = taskAllocation.WorkItem,
TenantId = taskAllocation.TenantId
};
}
public static CommentVM ToCommentVMFromTaskComment(this TaskComment comment)
{
return new CommentVM
{
Id = comment.Id,
TaskAllocationId = comment.TaskAllocationId,
CommentDate = comment.CommentDate,
Comment = comment.Comment,
CommentedBy = comment.CommentedBy,
Employee = comment.Employee.ToEmployeeVMFromEmployee()
};
}
}
}

View File

@ -1,13 +1,8 @@
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations.Schema;
using Marco.Pms.Model.Entitlements;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
namespace Marco.Pms.Model.Projects
{

View File

@ -1,4 +1,5 @@
using Marco.Pms.Model.ViewModels.Employee;
using Marco.Pms.Model.Activities;
using Marco.Pms.Model.ViewModels.Employee;
namespace Marco.Pms.Model.ViewModels.Activities

View File

@ -0,0 +1,14 @@
using Marco.Pms.Model.ViewModels.Employee;
namespace Marco.Pms.Model.ViewModels.Activities
{
public class CommentVM
{
public long Id { get; set; }
public long TaskAllocationId { get; set; }
public DateTime CommentDate { get; set; }
public string Comment { get; set; }
public int CommentedBy { get; set; }
public EmployeeVM? Employee { get; set; }
}
}

View File

@ -0,0 +1,19 @@
using Marco.Pms.Model.Projects;
using Marco.Pms.Model.ViewModels.Employee;
namespace Marco.Pms.Model.ViewModels.Activities
{
public class ListTaskVM
{
public long Id { get; set; }
public DateTime AssignmentDate { get; set; }
public double PlannedTask { get; set; }
public double CompletedTask { get; set; }
public EmployeeVM? AssignedBy { get; set; }
public int WorkItemId { get; set; }
public WorkItem? WorkItem { get; set; }
public int TenantId { get; set; }
public List<EmployeeVM> teamMembers { get; set; }
public List<CommentVM>? comments { get; set; }
}
}

View File

@ -80,10 +80,11 @@ namespace MarcoBMS.Services.Controllers
var idList = teamMembers.Select(m => m.EmployeeId);
List<Employee> employees = await _context.Employees.Where(e=> idList.Contains(e.Id)).ToListAsync();
List<EmployeeVM> team = new List<EmployeeVM>();
foreach (var employee in employees) {
response.teamMembers.Add(employee.ToEmployeeVMFromEmployee());
team.Add(employee.ToEmployeeVMFromEmployee());
}
response.teamMembers = team;
return Ok(ApiResponse<object>.SuccessResponse(response, "Task assignned successfully", 200));
}
@ -131,7 +132,8 @@ namespace MarcoBMS.Services.Controllers
_context.TaskComments.Add(comment);
await _context.SaveChangesAsync();
return Ok(ApiResponse<object>.SuccessResponse(comment, "Comment saved successfully", 200));
CommentVM response = comment.ToCommentVMFromTaskComment();
return Ok(ApiResponse<object>.SuccessResponse(response, "Comment saved successfully", 200));
}
[HttpGet("list")]
@ -151,8 +153,8 @@ namespace MarcoBMS.Services.Controllers
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid ending date.", "Invalid ending date.", 400));
}
if (dateTo == null) toDate = DateTime.UtcNow;
if (dateFrom == null) fromDate = toDate.AddDays(-1);
if (dateFrom == null) fromDate = DateTime.UtcNow.Date;
if (dateTo == null) toDate = fromDate.AddDays(1);
//var taskAllocations = await _context.TaskAllocations.Where(t => t.WorkItem.WorkArea.Floor.Building.ProjectId == projectId && t.AssignmentDate >= fromDate && t.AssignmentDate <= toDate && t.TenantId == tenantId).Include(t => t.WorkItemId).ToListAsync();
List<Building> buildings = await _context.Buildings.Where(b => b.ProjectId == projectId && b.TenantId == tenantId).ToListAsync();
@ -167,28 +169,34 @@ namespace MarcoBMS.Services.Controllers
List<WorkItem> workItems = await _context.WorkItems.Where(i => idList.Contains(i.WorkAreaId) && i.TenantId == tenantId).Include(i => i.ActivityMaster).ToListAsync();
idList = workAreas.Select(i => i.Id).ToList();
List<TaskAllocation> taskAllocations = await _context.TaskAllocations.Where(t => idList.Contains(t.WorkItemId) && t.AssignmentDate >= fromDate && t.AssignmentDate <= toDate && t.TenantId == tenantId).Include(t => t.WorkItem).ToListAsync();
//var taskAllocations = await (from t in _context.TaskAllocations
// join w in _context.WorkItems on t.WorkItemId equals w.Id
// join a in _context.ActivityMasters on w.ActivityId equals a.Id
// where t.WorkItem.WorkArea.Floor.Building.ProjectId == projectId && t.AssignmentDate >= fromDate && t.AssignmentDate <= toDate && t.TenantId == tenantId
// select new {TaskAllocation = t, WorkItems = w, ActivityMasters = a }).ToListAsync();
List<TasksVM> tasks = new List<TasksVM>();
List<TaskAllocation> taskAllocations = await _context.TaskAllocations.Where(t => idList.Contains(t.WorkItemId) && t.AssignmentDate >= fromDate && t.AssignmentDate <= toDate && t.TenantId == tenantId).Include(t => t.WorkItem).Include(t=>t.Employee).ToListAsync();
var taskIdList = taskAllocations.Select(t => t.Id).ToList();
List<TaskMembers> teamMembers = await _context.TaskMembers.Where(t => taskIdList.Contains(t.TaskAllocationId)).Include(t => t.Employee).ToListAsync();
List<ListTaskVM> tasks = new List<ListTaskVM>();
foreach (var workItem in workItems)
{
foreach (var taskAllocation in taskAllocations)
{
var result = new TasksVM
var response = taskAllocation.ToListTaskVMFromTaskAllocation();
List<TaskComment> comments = await _context.TaskComments.Where(c => c.TaskAllocationId == taskAllocation.Id).ToListAsync();
List<EmployeeVM> team = new List<EmployeeVM>();
foreach (var taskMember in teamMembers)
{
Id = workItem.ActivityMaster.Id,
ActivityName = workItem.ActivityMaster.ActivityName,
TotalPlannedTask = workItem.PlannedWork,
PlannedTask = taskAllocation.PlannedTask,
CompletedTask = taskAllocation.CompletedTask,
TotalCopmletedTask = workItem.CompletedWork
};
tasks.Add(result);
team.Add(taskMember.Employee.ToEmployeeVMFromEmployee());
}
List<CommentVM> commentVM = new List<CommentVM> { };
foreach (var comment in comments)
{
commentVM.Add(comment.ToCommentVMFromTaskComment());
}
response.comments = commentVM;
response.teamMembers = team;
tasks.Add(response);
}
}
return Ok(ApiResponse<object>.SuccessResponse(tasks, "Success", 200));
}