Firebase_Implementation #135
@ -57,58 +57,84 @@ namespace Marco.Pms.Services.Service
|
||||
}).FirstOrDefaultAsync();
|
||||
});
|
||||
|
||||
var roleTask = Task.Run(async () =>
|
||||
var teamAttendanceRoleTask = Task.Run(async () =>
|
||||
{
|
||||
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
return await dbContext.RolePermissionMappings
|
||||
.Where(rp => rp.FeaturePermissionId == PermissionsMaster.TeamAttendance)
|
||||
.Select(rp => rp.ApplicationRoleId).ToListAsync();
|
||||
});
|
||||
var manageProjectsRoleTask = Task.Run(async () =>
|
||||
{
|
||||
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
return await dbContext.RolePermissionMappings
|
||||
.Where(rp => rp.FeaturePermissionId == PermissionsMaster.ManageProject)
|
||||
.Select(rp => rp.ApplicationRoleId).ToListAsync();
|
||||
});
|
||||
|
||||
await Task.WhenAll(projectTask, roleTask);
|
||||
await Task.WhenAll(projectTask, teamAttendanceRoleTask, manageProjectsRoleTask);
|
||||
|
||||
var applicationRoleIds = roleTask.Result;
|
||||
var teamAttendanceRoleIds = teamAttendanceRoleTask.Result;
|
||||
var manageProjectsRoleIds = manageProjectsRoleTask.Result;
|
||||
var project = projectTask.Result;
|
||||
|
||||
List<Guid> projectAssignedEmployeeIds = project?.EmployeeIds ?? new List<Guid>();
|
||||
|
||||
var employeeIds = await _context.EmployeeRoleMappings
|
||||
.Where(er => projectAssignedEmployeeIds.Contains(er.EmployeeId) && applicationRoleIds.Contains(er.RoleId))
|
||||
.Where(er => (projectAssignedEmployeeIds.Contains(er.EmployeeId) || manageProjectsRoleIds.Contains(er.RoleId)) && teamAttendanceRoleIds.Contains(er.RoleId))
|
||||
.Select(er => er.RoleId)
|
||||
.ToListAsync();
|
||||
|
||||
string body;
|
||||
Notification notificationFirebase;
|
||||
switch (markType)
|
||||
{
|
||||
case ATTENDANCE_MARK_TYPE.CHECK_IN:
|
||||
body = $"{Name} Checked In for project {project?.ProjectName ?? ""}";
|
||||
notificationFirebase = new Notification
|
||||
{
|
||||
Title = "Attendance Update",
|
||||
Body = $" {Name} has checked in for project {project?.ProjectName ?? ""}."
|
||||
};
|
||||
break;
|
||||
case ATTENDANCE_MARK_TYPE.CHECK_OUT:
|
||||
body = $"{Name} Checked Out for project {project?.ProjectName ?? ""}";
|
||||
notificationFirebase = new Notification
|
||||
{
|
||||
Title = "Attendance Update",
|
||||
Body = $" {Name} has checked out for project {project?.ProjectName ?? ""}."
|
||||
};
|
||||
break;
|
||||
case ATTENDANCE_MARK_TYPE.REQUEST_REGULARIZE:
|
||||
body = $"{Name} Requested Regularization for project {project?.ProjectName ?? ""}";
|
||||
notificationFirebase = new Notification
|
||||
{
|
||||
Title = "Regularization Request",
|
||||
Body = $" {Name} has submitted a regularization request for project {project?.ProjectName ?? ""}."
|
||||
};
|
||||
break;
|
||||
case ATTENDANCE_MARK_TYPE.REGULARIZE:
|
||||
body = $"Regularization Accepted of {Name} for Project {project?.ProjectName ?? ""}";
|
||||
notificationFirebase = new Notification
|
||||
{
|
||||
Title = " Regularization Approved",
|
||||
Body = $" {Name}'s regularization request for project {project?.ProjectName ?? ""} has been accepted."
|
||||
};
|
||||
break;
|
||||
case ATTENDANCE_MARK_TYPE.REGULARIZE_REJECT:
|
||||
body = $"Regularization Rejected of {Name} for Project {project?.ProjectName ?? ""}";
|
||||
notificationFirebase = new Notification
|
||||
{
|
||||
Title = "Regularization Denied",
|
||||
Body = $" {Name}'s regularization request for project {project?.ProjectName ?? ""} has been rejected."
|
||||
};
|
||||
break;
|
||||
default:
|
||||
body = string.Empty;
|
||||
notificationFirebase = new Notification
|
||||
{
|
||||
Title = "Attendance Update",
|
||||
Body = $" {Name} has update his/her attendance for project {project?.ProjectName ?? ""}."
|
||||
};
|
||||
break;
|
||||
}
|
||||
|
||||
var notificationFirebase = new Notification
|
||||
{
|
||||
Title = "Attendance Marked",
|
||||
Body = body
|
||||
};
|
||||
|
||||
// List of device registration tokens to send the message to
|
||||
var registrationTokens = await _context.FCMTokenMappings
|
||||
//.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.TenantId == tenantId)
|
||||
.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.TenantId == tenantId)
|
||||
.Select(ft => ft.FcmToken).ToListAsync();
|
||||
|
||||
await SendMessageToMultipleDevicesAsync(registrationTokens, notificationFirebase);
|
||||
|
Loading…
x
Reference in New Issue
Block a user