Compare commits
1 Commits
main
...
pramod_Tas
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ed4889d300 |
@ -61,6 +61,19 @@ namespace Marco.Pms.Model.Mapper
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ProjectAllocation ToProjectAllocationOrDeallocationFromProjectAllocationDto(this ProjectAllocationDot model, Guid TenantId,Guid employeeId)
|
||||||
|
{
|
||||||
|
return new ProjectAllocation
|
||||||
|
{
|
||||||
|
AllocationDate = DateTime.Now,
|
||||||
|
EmployeeId = employeeId,
|
||||||
|
JobRoleId = model.JobRoleId,
|
||||||
|
TenantId = TenantId,
|
||||||
|
ProjectId = model.ProjectId
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public static ProjectListVM ToProjectListVMFromProject(this Project project)
|
public static ProjectListVM ToProjectListVMFromProject(this Project project)
|
||||||
{
|
{
|
||||||
return new ProjectListVM
|
return new ProjectListVM
|
||||||
|
@ -665,14 +665,14 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<Guid> projectList = await _context.ProjectAllocations
|
List<Guid> projectList = await _context.ProjectAllocations
|
||||||
.Where(c => c.TenantId == tenantId && c.EmployeeId == employeeId)
|
.Where(c => c.TenantId == tenantId && c.EmployeeId == employeeId && c.IsActive == true)
|
||||||
.Select(c => c.ProjectId).Distinct()
|
.Select(c => c.ProjectId).Distinct()
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
if (!projectList.Any())
|
//if (!projectList.Any())
|
||||||
{
|
//{
|
||||||
return NotFound(ApiResponse<object>.SuccessResponse(new List<object>(), "No projects found.",404));
|
// return NotFound(ApiResponse<object>.SuccessResponse(new List<object>(), "No projects found.",404));
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
List<Project> projectlist = await _context.Projects
|
List<Project> projectlist = await _context.Projects
|
||||||
@ -691,8 +691,91 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
|
|
||||||
return Ok(ApiResponse<object>.SuccessResponse(projects, "Success.", 200));
|
return Ok(ApiResponse<object>.SuccessResponse(projects, "Success.", 200));
|
||||||
}
|
}
|
||||||
|
[HttpPost("assign-projects/{employeeId}")]
|
||||||
|
public async Task<IActionResult> AssignOrUnassigendToProject([FromBody] List<ProjectAllocationDot> projectAllocationDots, [FromRoute] Guid employeeId)
|
||||||
|
{
|
||||||
|
Guid tenantId = _userHelper.GetTenantId();
|
||||||
|
|
||||||
|
|
||||||
|
if (projectAllocationDots != null)
|
||||||
|
{
|
||||||
|
Guid TenentID = GetTenantId();
|
||||||
|
List<object>? result = new List<object>();
|
||||||
|
|
||||||
|
foreach (var item in projectAllocationDots)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ProjectAllocation projectAllocation = item.ToProjectAllocationFromProjectAllocationDto(TenentID);
|
||||||
|
ProjectAllocation? projectAllocationFromDb = await _context.ProjectAllocations.Where(c => c.EmployeeId == projectAllocation.EmployeeId
|
||||||
|
&& c.ProjectId == projectAllocation.ProjectId
|
||||||
|
&& c.ReAllocationDate == null
|
||||||
|
&& c.TenantId == TenentID).SingleOrDefaultAsync();
|
||||||
|
|
||||||
|
if (projectAllocationFromDb != null)
|
||||||
|
{
|
||||||
|
_context.ProjectAllocations.Attach(projectAllocationFromDb);
|
||||||
|
|
||||||
|
if (item.Status)
|
||||||
|
{
|
||||||
|
projectAllocationFromDb.JobRoleId = projectAllocation.JobRoleId; ;
|
||||||
|
projectAllocationFromDb.IsActive = true;
|
||||||
|
_context.Entry(projectAllocationFromDb).Property(e => e.JobRoleId).IsModified = true;
|
||||||
|
_context.Entry(projectAllocationFromDb).Property(e => e.IsActive).IsModified = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
projectAllocationFromDb.ReAllocationDate = DateTime.Now;
|
||||||
|
projectAllocationFromDb.IsActive = false;
|
||||||
|
_context.Entry(projectAllocationFromDb).Property(e => e.ReAllocationDate).IsModified = true;
|
||||||
|
_context.Entry(projectAllocationFromDb).Property(e => e.IsActive).IsModified = true;
|
||||||
|
}
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
var result1 = new
|
||||||
|
{
|
||||||
|
Id = projectAllocationFromDb.Id,
|
||||||
|
EmployeeId = projectAllocation.EmployeeId,
|
||||||
|
JobRoleId = projectAllocation.JobRoleId,
|
||||||
|
IsActive = projectAllocation.IsActive,
|
||||||
|
ProjectId = projectAllocation.ProjectId,
|
||||||
|
AllocationDate = projectAllocation.AllocationDate,
|
||||||
|
ReAllocationDate = projectAllocation.ReAllocationDate,
|
||||||
|
TenantId = projectAllocation.TenantId
|
||||||
|
};
|
||||||
|
result.Add(result1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
projectAllocation.AllocationDate = DateTime.Now;
|
||||||
|
projectAllocation.IsActive = true;
|
||||||
|
_context.ProjectAllocations.Add(projectAllocation);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
var result1 = new
|
||||||
|
{
|
||||||
|
Id = projectAllocation.Id,
|
||||||
|
EmployeeId = projectAllocation.EmployeeId,
|
||||||
|
JobRoleId = projectAllocation.JobRoleId,
|
||||||
|
IsActive = projectAllocation.IsActive,
|
||||||
|
ProjectId = projectAllocation.ProjectId,
|
||||||
|
AllocationDate = projectAllocation.AllocationDate,
|
||||||
|
ReAllocationDate = projectAllocation.ReAllocationDate,
|
||||||
|
TenantId = projectAllocation.TenantId
|
||||||
|
};
|
||||||
|
result.Add(result1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Ok(ApiResponse<object>.ErrorResponse(ex.Message, ex, 400));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(ApiResponse<object>.SuccessResponse(result, "Data saved successfully", 200));
|
||||||
|
|
||||||
|
}
|
||||||
|
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid details.", "Work Item Details are not valid.", 400));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user