Sending the attendance data notification to all employees from the project
This commit is contained in:
parent
20b12cfcd4
commit
9d71a71a53
@ -120,12 +120,28 @@ namespace Marco.Pms.Services.Service
|
|||||||
|
|
||||||
List<Guid> projectAssignedEmployeeIds = project?.EmployeeIds ?? new List<Guid>();
|
List<Guid> projectAssignedEmployeeIds = project?.EmployeeIds ?? new List<Guid>();
|
||||||
|
|
||||||
var employeeIds = await _context.EmployeeRoleMappings
|
var employeeIdsTask = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||||
|
return await dbContext.EmployeeRoleMappings
|
||||||
.Where(er => (projectAssignedEmployeeIds.Contains(er.EmployeeId) || manageProjectsRoleIds.Contains(er.RoleId)) && teamAttendanceRoleIds.Contains(er.RoleId))
|
.Where(er => (projectAssignedEmployeeIds.Contains(er.EmployeeId) || manageProjectsRoleIds.Contains(er.RoleId)) && teamAttendanceRoleIds.Contains(er.RoleId))
|
||||||
.Select(er => er.EmployeeId)
|
.Select(er => er.EmployeeId)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
});
|
||||||
|
var teamEmployeeIdsTask = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||||
|
return await dbContext.EmployeeRoleMappings
|
||||||
|
.Where(er => projectAssignedEmployeeIds.Contains(er.EmployeeId) || manageProjectsRoleIds.Contains(er.RoleId))
|
||||||
|
.Select(er => er.EmployeeId)
|
||||||
|
.ToListAsync();
|
||||||
|
});
|
||||||
|
|
||||||
|
await Task.WhenAll(employeeIdsTask, teamEmployeeIdsTask);
|
||||||
|
|
||||||
|
var employeeIds = employeeIdsTask.Result;
|
||||||
|
var teamEmployeeIds = teamEmployeeIdsTask.Result;
|
||||||
|
|
||||||
var dataNotificationIds = new List<Guid>();
|
|
||||||
var mesaageNotificationIds = new List<Guid>();
|
var mesaageNotificationIds = new List<Guid>();
|
||||||
|
|
||||||
Notification notificationFirebase;
|
Notification notificationFirebase;
|
||||||
@ -157,7 +173,6 @@ namespace Marco.Pms.Services.Service
|
|||||||
.Where(er => (projectAssignedEmployeeIds.Contains(er.EmployeeId) || manageProjectsRoleIds.Contains(er.RoleId)) && regularizeAttendanceRoleIds.Contains(er.RoleId))
|
.Where(er => (projectAssignedEmployeeIds.Contains(er.EmployeeId) || manageProjectsRoleIds.Contains(er.RoleId)) && regularizeAttendanceRoleIds.Contains(er.RoleId))
|
||||||
.Select(er => er.EmployeeId)
|
.Select(er => er.EmployeeId)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
dataNotificationIds = employeeIds;
|
|
||||||
break;
|
break;
|
||||||
case ATTENDANCE_MARK_TYPE.REGULARIZE:
|
case ATTENDANCE_MARK_TYPE.REGULARIZE:
|
||||||
notificationFirebase = new Notification
|
notificationFirebase = new Notification
|
||||||
@ -166,7 +181,6 @@ namespace Marco.Pms.Services.Service
|
|||||||
Body = $" {name}'s regularization request for project {project?.ProjectName ?? ""} has been accepted."
|
Body = $" {name}'s regularization request for project {project?.ProjectName ?? ""} has been accepted."
|
||||||
};
|
};
|
||||||
mesaageNotificationIds.Add(employeeId);
|
mesaageNotificationIds.Add(employeeId);
|
||||||
dataNotificationIds.AddRange(employeeIds);
|
|
||||||
break;
|
break;
|
||||||
case ATTENDANCE_MARK_TYPE.REGULARIZE_REJECT:
|
case ATTENDANCE_MARK_TYPE.REGULARIZE_REJECT:
|
||||||
notificationFirebase = new Notification
|
notificationFirebase = new Notification
|
||||||
@ -175,7 +189,6 @@ namespace Marco.Pms.Services.Service
|
|||||||
Body = $" {name}'s regularization request for project {project?.ProjectName ?? ""} has been rejected."
|
Body = $" {name}'s regularization request for project {project?.ProjectName ?? ""} has been rejected."
|
||||||
};
|
};
|
||||||
mesaageNotificationIds.Add(employeeId);
|
mesaageNotificationIds.Add(employeeId);
|
||||||
dataNotificationIds.AddRange(employeeIds);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
notificationFirebase = new Notification
|
notificationFirebase = new Notification
|
||||||
@ -207,10 +220,10 @@ namespace Marco.Pms.Services.Service
|
|||||||
});
|
});
|
||||||
var registrationTokensForDataTask = Task.Run(async () =>
|
var registrationTokensForDataTask = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
if (dataNotificationIds.Any())
|
if (teamEmployeeIds.Any())
|
||||||
{
|
{
|
||||||
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||||
var registrationTokensForData = await dbContext.FCMTokenMappings.Where(ft => dataNotificationIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForData = await dbContext.FCMTokenMappings.Where(ft => teamEmployeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesOnlyDataAsync(registrationTokensForData, data);
|
await SendMessageToMultipleDevicesOnlyDataAsync(registrationTokensForData, data);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user