Ashutosh_Task#513 #96

Merged
ashutosh.nehete merged 58 commits from Ashutosh_Task#513 into Issues_June_3W 2025-06-28 04:27:28 +00:00
Showing only changes of commit 29ea1698bc - Show all commits

View File

@ -63,9 +63,9 @@ namespace MarcoBMS.Services.Controllers
return Unauthorized(ApiResponse<object>.ErrorResponse("Employee not found.", null, 401)); return Unauthorized(ApiResponse<object>.ErrorResponse("Employee not found.", null, 401));
} }
List<Project> projects = await _projectsHelper.GetMyProjects(tenantId, LoggedInEmployee); List<Project> projects = await _projectsHelper.GetMyProjects(tenantId, LoggedInEmployee);
// 4. Project projection to ProjectInfoVM // 4. Project projection to ProjectInfoVM
// This part is already quite efficient. // This part is already quite efficient.
@ -88,7 +88,7 @@ namespace MarcoBMS.Services.Controllers
return Ok(ApiResponse<object>.SuccessResponse(response, "Success.", 200)); return Ok(ApiResponse<object>.SuccessResponse(response, "Success.", 200));
} }
[HttpGet("list")] [HttpGet("list")]
public async Task<IActionResult> GetAll() public async Task<IActionResult> GetAll()
@ -518,7 +518,11 @@ namespace MarcoBMS.Services.Controllers
if (projectAllocationDot != null) if (projectAllocationDot != null)
{ {
Guid TenentID = GetTenantId(); Guid TenentID = GetTenantId();
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
List<object>? result = new List<object>(); List<object>? result = new List<object>();
List<Guid> employeeIds = new List<Guid>();
List<Guid> projectIds = new List<Guid>();
foreach (var item in projectAllocationDot) foreach (var item in projectAllocationDot)
{ {
@ -547,6 +551,9 @@ namespace MarcoBMS.Services.Controllers
projectAllocationFromDb.IsActive = false; projectAllocationFromDb.IsActive = false;
_context.Entry(projectAllocationFromDb).Property(e => e.ReAllocationDate).IsModified = true; _context.Entry(projectAllocationFromDb).Property(e => e.ReAllocationDate).IsModified = true;
_context.Entry(projectAllocationFromDb).Property(e => e.IsActive).IsModified = true; _context.Entry(projectAllocationFromDb).Property(e => e.IsActive).IsModified = true;
employeeIds.Add(projectAllocation.EmployeeId);
projectIds.Add(projectAllocation.ProjectId);
} }
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
var result1 = new var result1 = new
@ -568,15 +575,21 @@ namespace MarcoBMS.Services.Controllers
projectAllocation.IsActive = true; projectAllocation.IsActive = true;
_context.ProjectAllocations.Add(projectAllocation); _context.ProjectAllocations.Add(projectAllocation);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
employeeIds.Add(projectAllocation.EmployeeId);
projectIds.Add(projectAllocation.ProjectId);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
return Ok(ApiResponse<object>.ErrorResponse(ex.Message, ex, 400)); return Ok(ApiResponse<object>.ErrorResponse(ex.Message, ex, 400));
} }
} }
var notification = new { LoggedInUserId = LoggedInEmployee.Id, Keyword = "Assign_Project", ProjectIds = projectIds, EmployeeList = employeeIds };
await _signalR.Clients.All.SendAsync("NotificationEventHandler", notification);
return Ok(ApiResponse<object>.SuccessResponse(result, "Data saved successfully", 200)); return Ok(ApiResponse<object>.SuccessResponse(result, "Data saved successfully", 200));
} }
@ -590,6 +603,7 @@ namespace MarcoBMS.Services.Controllers
Guid tenantId = GetTenantId(); Guid tenantId = GetTenantId();
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync(); var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
List<WorkItemVM> workItems = new List<WorkItemVM> { }; List<WorkItemVM> workItems = new List<WorkItemVM> { };
Building building = new Building();
string responseMessage = ""; string responseMessage = "";
if (workItemDot != null) if (workItemDot != null)
{ {
@ -597,6 +611,10 @@ namespace MarcoBMS.Services.Controllers
{ {
WorkItem workItem = item.ToWorkItemFromWorkItemDto(tenantId); WorkItem workItem = item.ToWorkItemFromWorkItemDto(tenantId);
var workArea = await _context.WorkAreas.Include(a => a.Floor).FirstOrDefaultAsync(a => a.Id == workItem.WorkAreaId) ?? new WorkArea();
building = await _context.Buildings.FirstOrDefaultAsync(b => b.Id == (workArea.Floor != null ? workArea.Floor.BuildingId : Guid.Empty)) ?? new Building();
if (item.Id != null) if (item.Id != null)
{ {
//update //update
@ -621,7 +639,7 @@ namespace MarcoBMS.Services.Controllers
var activity = await _context.ActivityMasters.ToListAsync(); var activity = await _context.ActivityMasters.ToListAsync();
var category = await _context.WorkCategoryMasters.ToListAsync(); var category = await _context.WorkCategoryMasters.ToListAsync();
var notification = new { LoggedInUserId = LoggedInEmployee.Id, Keyword = "Infra", Response = workItems }; var notification = new { LoggedInUserId = LoggedInEmployee.Id, Keyword = "Infra", ProjectId = building.ProjectId };
await _signalR.Clients.All.SendAsync("NotificationEventHandler", notification); await _signalR.Clients.All.SendAsync("NotificationEventHandler", notification);
return Ok(ApiResponse<object>.SuccessResponse(workItems, responseMessage, 200)); return Ok(ApiResponse<object>.SuccessResponse(workItems, responseMessage, 200));
@ -808,7 +826,9 @@ namespace MarcoBMS.Services.Controllers
if (projectAllocationDtos != null && employeeId != Guid.Empty) if (projectAllocationDtos != null && employeeId != Guid.Empty)
{ {
Guid TenentID = GetTenantId(); Guid TenentID = GetTenantId();
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
List<object>? result = new List<object>(); List<object>? result = new List<object>();
List<Guid> projectIds = new List<Guid>();
foreach (var projectAllocationDto in projectAllocationDtos) foreach (var projectAllocationDto in projectAllocationDtos)
{ {
@ -836,6 +856,8 @@ namespace MarcoBMS.Services.Controllers
projectAllocationFromDb.IsActive = false; projectAllocationFromDb.IsActive = false;
_context.Entry(projectAllocationFromDb).Property(e => e.ReAllocationDate).IsModified = true; _context.Entry(projectAllocationFromDb).Property(e => e.ReAllocationDate).IsModified = true;
_context.Entry(projectAllocationFromDb).Property(e => e.IsActive).IsModified = true; _context.Entry(projectAllocationFromDb).Property(e => e.IsActive).IsModified = true;
projectIds.Add(projectAllocation.ProjectId);
} }
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
var result1 = new var result1 = new
@ -858,6 +880,8 @@ namespace MarcoBMS.Services.Controllers
_context.ProjectAllocations.Add(projectAllocation); _context.ProjectAllocations.Add(projectAllocation);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
projectIds.Add(projectAllocation.ProjectId);
} }
@ -868,6 +892,9 @@ namespace MarcoBMS.Services.Controllers
return Ok(ApiResponse<object>.ErrorResponse(ex.Message, ex, 400)); return Ok(ApiResponse<object>.ErrorResponse(ex.Message, ex, 400));
} }
} }
var notification = new { LoggedInUserId = LoggedInEmployee.Id, Keyword = "Assign_Project", ProjectIds = projectIds, EmployeeId = employeeId };
await _signalR.Clients.All.SendAsync("NotificationEventHandler", notification);
return Ok(ApiResponse<object>.SuccessResponse(result, "Data saved successfully", 200)); return Ok(ApiResponse<object>.SuccessResponse(result, "Data saved successfully", 200));
} }