Added signalR functionality in Project Infrastructure
This commit is contained in:
parent
39378f3a88
commit
e2956c0c8c
@ -88,8 +88,6 @@ 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()
|
||||||
{
|
{
|
||||||
@ -603,7 +601,8 @@ 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();
|
List<Guid> projectIds = new List<Guid>();
|
||||||
|
string message = "";
|
||||||
string responseMessage = "";
|
string responseMessage = "";
|
||||||
if (workItemDot != null)
|
if (workItemDot != null)
|
||||||
{
|
{
|
||||||
@ -613,21 +612,23 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
|
|
||||||
var workArea = await _context.WorkAreas.Include(a => a.Floor).FirstOrDefaultAsync(a => a.Id == workItem.WorkAreaId) ?? new WorkArea();
|
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();
|
Building 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
|
||||||
_context.WorkItems.Update(workItem);
|
_context.WorkItems.Update(workItem);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
responseMessage = "Task Added Successfully";
|
responseMessage = "Task Updated Successfully";
|
||||||
|
message = $"Task Updated by {LoggedInEmployee.FirstName} {LoggedInEmployee.LastName}";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//create
|
//create
|
||||||
_context.WorkItems.Add(workItem);
|
_context.WorkItems.Add(workItem);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
responseMessage = "Task Updated Successfully";
|
responseMessage = "Task Added Successfully";
|
||||||
|
message = $"Task Added by {LoggedInEmployee.FirstName} {LoggedInEmployee.LastName}";
|
||||||
}
|
}
|
||||||
var result = new WorkItemVM
|
var result = new WorkItemVM
|
||||||
{
|
{
|
||||||
@ -635,11 +636,12 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
WorkItem = workItem
|
WorkItem = workItem
|
||||||
};
|
};
|
||||||
workItems.Add(result);
|
workItems.Add(result);
|
||||||
|
projectIds.Add(building.ProjectId);
|
||||||
}
|
}
|
||||||
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", ProjectId = building.ProjectId };
|
var notification = new { LoggedInUserId = LoggedInEmployee.Id, Keyword = "Infra", ProjectIds = projectIds, Message = message };
|
||||||
|
|
||||||
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));
|
||||||
@ -654,7 +656,8 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
{
|
{
|
||||||
Guid tenantId = _userHelper.GetTenantId();
|
Guid tenantId = _userHelper.GetTenantId();
|
||||||
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||||
WorkItem? task = await _context.WorkItems.AsNoTracking().FirstOrDefaultAsync(t => t.Id == id && t.TenantId == tenantId);
|
List<Guid> projectIds = new List<Guid>();
|
||||||
|
WorkItem? task = await _context.WorkItems.AsNoTracking().Include(t => t.WorkArea).FirstOrDefaultAsync(t => t.Id == id && t.TenantId == tenantId);
|
||||||
if (task != null)
|
if (task != null)
|
||||||
{
|
{
|
||||||
if (task.CompletedWork == 0)
|
if (task.CompletedWork == 0)
|
||||||
@ -666,7 +669,13 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
_logger.LogInfo("Task with ID {WorkItemId} has been successfully deleted.", task.Id);
|
_logger.LogInfo("Task with ID {WorkItemId} has been successfully deleted.", task.Id);
|
||||||
|
|
||||||
var notification = new { LoggedInUserId = LoggedInEmployee.Id, Keyword = "Infra", Response = id };
|
var floorId = task.WorkArea?.FloorId;
|
||||||
|
var floor = await _context.Floor.Include(f => f.Building).FirstOrDefaultAsync(f => f.Id == floorId);
|
||||||
|
|
||||||
|
|
||||||
|
projectIds.Add(floor?.Building?.ProjectId ?? Guid.Empty);
|
||||||
|
|
||||||
|
var notification = new { LoggedInUserId = LoggedInEmployee.Id, Keyword = "Infra", ProjectIds = projectIds, Message = $"Task Deleted by {LoggedInEmployee.FirstName} {LoggedInEmployee.LastName}" };
|
||||||
await _signalR.Clients.All.SendAsync("NotificationEventHandler", notification);
|
await _signalR.Clients.All.SendAsync("NotificationEventHandler", notification);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -699,6 +708,8 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
|
|
||||||
var responseData = new InfraVM { };
|
var responseData = new InfraVM { };
|
||||||
string responseMessage = "";
|
string responseMessage = "";
|
||||||
|
string message = "";
|
||||||
|
List<Guid> projectIds = new List<Guid>();
|
||||||
if (infraDots != null)
|
if (infraDots != null)
|
||||||
{
|
{
|
||||||
foreach (var item in infraDots)
|
foreach (var item in infraDots)
|
||||||
@ -716,6 +727,7 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
responseData.building = building;
|
responseData.building = building;
|
||||||
responseMessage = "Buliding Added Successfully";
|
responseMessage = "Buliding Added Successfully";
|
||||||
|
message = "Building Added";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -724,8 +736,10 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
responseData.building = building;
|
responseData.building = building;
|
||||||
responseMessage = "Buliding Updated Successfully";
|
responseMessage = "Buliding Updated Successfully";
|
||||||
|
message = "Building Updated";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
projectIds.Add(building.ProjectId);
|
||||||
}
|
}
|
||||||
if (item.Floor != null)
|
if (item.Floor != null)
|
||||||
{
|
{
|
||||||
@ -739,6 +753,7 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
responseData.floor = floor;
|
responseData.floor = floor;
|
||||||
responseMessage = "Floor Added Successfully";
|
responseMessage = "Floor Added Successfully";
|
||||||
|
message = "Floor Added";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -747,7 +762,10 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
responseData.floor = floor;
|
responseData.floor = floor;
|
||||||
responseMessage = "Floor Updated Successfully";
|
responseMessage = "Floor Updated Successfully";
|
||||||
|
message = "Floor Updated";
|
||||||
}
|
}
|
||||||
|
Building? building = await _context.Buildings.FirstOrDefaultAsync(b => b.Id == floor.BuildingId);
|
||||||
|
projectIds.Add(building?.ProjectId ?? Guid.Empty);
|
||||||
}
|
}
|
||||||
if (item.WorkArea != null)
|
if (item.WorkArea != null)
|
||||||
{
|
{
|
||||||
@ -761,6 +779,7 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
responseData.workArea = workArea;
|
responseData.workArea = workArea;
|
||||||
responseMessage = "Work Area Added Successfully";
|
responseMessage = "Work Area Added Successfully";
|
||||||
|
message = "Work Area Added";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -769,10 +788,14 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
responseData.workArea = workArea;
|
responseData.workArea = workArea;
|
||||||
responseMessage = "Work Area Updated Successfully";
|
responseMessage = "Work Area Updated Successfully";
|
||||||
|
message = "Work Area Updated";
|
||||||
}
|
}
|
||||||
|
Floor? floor = await _context.Floor.Include(f => f.Building).FirstOrDefaultAsync(f => f.Id == workArea.FloorId);
|
||||||
|
projectIds.Add(floor?.Building?.ProjectId ?? Guid.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var notification = new { LoggedInUserId = LoggedInEmployee.Id, Keyword = "Infra", Response = responseData };
|
message = $"{message} by {LoggedInEmployee.FirstName} {LoggedInEmployee.LastName}";
|
||||||
|
var notification = new { LoggedInUserId = LoggedInEmployee.Id, Keyword = "Infra", ProjectIds = projectIds, Message = message };
|
||||||
|
|
||||||
await _signalR.Clients.All.SendAsync("NotificationEventHandler", notification);
|
await _signalR.Clients.All.SendAsync("NotificationEventHandler", notification);
|
||||||
return Ok(ApiResponse<object>.SuccessResponse(responseData, responseMessage, 200));
|
return Ok(ApiResponse<object>.SuccessResponse(responseData, responseMessage, 200));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user