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>();
|
||||
|
||||
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))
|
||||
.Select(er => er.EmployeeId)
|
||||
.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>();
|
||||
|
||||
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))
|
||||
.Select(er => er.EmployeeId)
|
||||
.ToListAsync();
|
||||
dataNotificationIds = employeeIds;
|
||||
break;
|
||||
case ATTENDANCE_MARK_TYPE.REGULARIZE:
|
||||
notificationFirebase = new Notification
|
||||
@ -166,7 +181,6 @@ namespace Marco.Pms.Services.Service
|
||||
Body = $" {name}'s regularization request for project {project?.ProjectName ?? ""} has been accepted."
|
||||
};
|
||||
mesaageNotificationIds.Add(employeeId);
|
||||
dataNotificationIds.AddRange(employeeIds);
|
||||
break;
|
||||
case ATTENDANCE_MARK_TYPE.REGULARIZE_REJECT:
|
||||
notificationFirebase = new Notification
|
||||
@ -175,7 +189,6 @@ namespace Marco.Pms.Services.Service
|
||||
Body = $" {name}'s regularization request for project {project?.ProjectName ?? ""} has been rejected."
|
||||
};
|
||||
mesaageNotificationIds.Add(employeeId);
|
||||
dataNotificationIds.AddRange(employeeIds);
|
||||
break;
|
||||
default:
|
||||
notificationFirebase = new Notification
|
||||
@ -207,10 +220,10 @@ namespace Marco.Pms.Services.Service
|
||||
});
|
||||
var registrationTokensForDataTask = Task.Run(async () =>
|
||||
{
|
||||
if (dataNotificationIds.Any())
|
||||
if (teamEmployeeIds.Any())
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user