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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpGet("list")]
|
||||
public async Task<IActionResult> GetAll()
|
||||
{
|
||||
@ -603,7 +601,8 @@ namespace MarcoBMS.Services.Controllers
|
||||
Guid tenantId = GetTenantId();
|
||||
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
List<WorkItemVM> workItems = new List<WorkItemVM> { };
|
||||
Building building = new Building();
|
||||
List<Guid> projectIds = new List<Guid>();
|
||||
string message = "";
|
||||
string responseMessage = "";
|
||||
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();
|
||||
|
||||
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)
|
||||
{
|
||||
//update
|
||||
_context.WorkItems.Update(workItem);
|
||||
await _context.SaveChangesAsync();
|
||||
responseMessage = "Task Added Successfully";
|
||||
responseMessage = "Task Updated Successfully";
|
||||
message = $"Task Updated by {LoggedInEmployee.FirstName} {LoggedInEmployee.LastName}";
|
||||
}
|
||||
else
|
||||
{
|
||||
//create
|
||||
_context.WorkItems.Add(workItem);
|
||||
await _context.SaveChangesAsync();
|
||||
responseMessage = "Task Updated Successfully";
|
||||
responseMessage = "Task Added Successfully";
|
||||
message = $"Task Added by {LoggedInEmployee.FirstName} {LoggedInEmployee.LastName}";
|
||||
}
|
||||
var result = new WorkItemVM
|
||||
{
|
||||
@ -635,11 +636,12 @@ namespace MarcoBMS.Services.Controllers
|
||||
WorkItem = workItem
|
||||
};
|
||||
workItems.Add(result);
|
||||
projectIds.Add(building.ProjectId);
|
||||
}
|
||||
var activity = await _context.ActivityMasters.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);
|
||||
return Ok(ApiResponse<object>.SuccessResponse(workItems, responseMessage, 200));
|
||||
@ -654,7 +656,8 @@ namespace MarcoBMS.Services.Controllers
|
||||
{
|
||||
Guid tenantId = _userHelper.GetTenantId();
|
||||
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.CompletedWork == 0)
|
||||
@ -666,7 +669,13 @@ namespace MarcoBMS.Services.Controllers
|
||||
await _context.SaveChangesAsync();
|
||||
_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);
|
||||
}
|
||||
else
|
||||
@ -699,6 +708,8 @@ namespace MarcoBMS.Services.Controllers
|
||||
|
||||
var responseData = new InfraVM { };
|
||||
string responseMessage = "";
|
||||
string message = "";
|
||||
List<Guid> projectIds = new List<Guid>();
|
||||
if (infraDots != null)
|
||||
{
|
||||
foreach (var item in infraDots)
|
||||
@ -716,6 +727,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
await _context.SaveChangesAsync();
|
||||
responseData.building = building;
|
||||
responseMessage = "Buliding Added Successfully";
|
||||
message = "Building Added";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -724,8 +736,10 @@ namespace MarcoBMS.Services.Controllers
|
||||
await _context.SaveChangesAsync();
|
||||
responseData.building = building;
|
||||
responseMessage = "Buliding Updated Successfully";
|
||||
message = "Building Updated";
|
||||
|
||||
}
|
||||
projectIds.Add(building.ProjectId);
|
||||
}
|
||||
if (item.Floor != null)
|
||||
{
|
||||
@ -739,6 +753,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
await _context.SaveChangesAsync();
|
||||
responseData.floor = floor;
|
||||
responseMessage = "Floor Added Successfully";
|
||||
message = "Floor Added";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -747,7 +762,10 @@ namespace MarcoBMS.Services.Controllers
|
||||
await _context.SaveChangesAsync();
|
||||
responseData.floor = floor;
|
||||
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)
|
||||
{
|
||||
@ -761,6 +779,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
await _context.SaveChangesAsync();
|
||||
responseData.workArea = workArea;
|
||||
responseMessage = "Work Area Added Successfully";
|
||||
message = "Work Area Added";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -769,10 +788,14 @@ namespace MarcoBMS.Services.Controllers
|
||||
await _context.SaveChangesAsync();
|
||||
responseData.workArea = workArea;
|
||||
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);
|
||||
return Ok(ApiResponse<object>.SuccessResponse(responseData, responseMessage, 200));
|
||||
|
Loading…
x
Reference in New Issue
Block a user