Added the data notification in delete employee API
This commit is contained in:
parent
a1ab143df5
commit
eba1a70037
@ -33,6 +33,7 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
{
|
{
|
||||||
|
|
||||||
private readonly ApplicationDbContext _context;
|
private readonly ApplicationDbContext _context;
|
||||||
|
private readonly IServiceScopeFactory _serviceScope;
|
||||||
private readonly UserManager<ApplicationUser> _userManager;
|
private readonly UserManager<ApplicationUser> _userManager;
|
||||||
private readonly IEmailSender _emailSender;
|
private readonly IEmailSender _emailSender;
|
||||||
private readonly EmployeeHelper _employeeHelper;
|
private readonly EmployeeHelper _employeeHelper;
|
||||||
@ -47,10 +48,21 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
private readonly Guid tenantId;
|
private readonly Guid tenantId;
|
||||||
|
|
||||||
|
|
||||||
public EmployeeController(UserManager<ApplicationUser> userManager, IEmailSender emailSender,
|
public EmployeeController(IServiceScopeFactory serviceScope,
|
||||||
ApplicationDbContext context, EmployeeHelper employeeHelper, UserHelper userHelper, IConfiguration configuration, ILoggingService logger,
|
UserManager<ApplicationUser> userManager,
|
||||||
IHubContext<MarcoHub> signalR, PermissionServices permission, IProjectServices projectServices, IMapper mapper, GeneralHelper generalHelper)
|
IEmailSender emailSender,
|
||||||
|
ApplicationDbContext context,
|
||||||
|
EmployeeHelper employeeHelper,
|
||||||
|
UserHelper userHelper,
|
||||||
|
IConfiguration configuration,
|
||||||
|
ILoggingService logger,
|
||||||
|
IHubContext<MarcoHub> signalR,
|
||||||
|
PermissionServices permission,
|
||||||
|
IProjectServices projectServices,
|
||||||
|
IMapper mapper,
|
||||||
|
GeneralHelper generalHelper)
|
||||||
{
|
{
|
||||||
|
_serviceScope = serviceScope;
|
||||||
_context = context;
|
_context = context;
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
_emailSender = emailSender;
|
_emailSender = emailSender;
|
||||||
@ -519,6 +531,8 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
[HttpDelete("{id}")]
|
[HttpDelete("{id}")]
|
||||||
public async Task<IActionResult> SuspendEmployee(Guid id, [FromQuery] bool active = false)
|
public async Task<IActionResult> SuspendEmployee(Guid id, [FromQuery] bool active = false)
|
||||||
{
|
{
|
||||||
|
using var scope = _serviceScope.CreateScope();
|
||||||
|
|
||||||
Guid tenantId = _userHelper.GetTenantId();
|
Guid tenantId = _userHelper.GetTenantId();
|
||||||
var LoggedEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
var LoggedEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||||
Employee? employee = await _context.Employees.FirstOrDefaultAsync(e => e.Id == id && e.TenantId == tenantId);
|
Employee? employee = await _context.Employees.FirstOrDefaultAsync(e => e.Id == id && e.TenantId == tenantId);
|
||||||
@ -602,6 +616,19 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
_logger.LogInfo("Application role mapping associated with employee ID {EmployeeId} has been removed.", employee.Id);
|
_logger.LogInfo("Application role mapping associated with employee ID {EmployeeId} has been removed.", employee.Id);
|
||||||
}
|
}
|
||||||
_logger.LogInfo("Employee with ID {EmployeId} Deleted successfully", employee.Id);
|
_logger.LogInfo("Employee with ID {EmployeId} Deleted successfully", employee.Id);
|
||||||
|
|
||||||
|
var _firebase = scope.ServiceProvider.GetRequiredService<IFirebaseService>();
|
||||||
|
|
||||||
|
_ = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
// --- Push Notification Section ---
|
||||||
|
// This section attempts to send a test push notification to the user's device.
|
||||||
|
// It's designed to fail gracefully and handle invalid Firebase Cloud Messaging (FCM) tokens.
|
||||||
|
|
||||||
|
await _firebase.SendEmployeeSuspendMessageAsync(employee.Id, tenantId);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,7 @@ namespace Marco.Pms.Services.Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Auth Controller
|
// Auth Controller
|
||||||
public async Task SendLoginOnAnotherDeviceMessageAsync(Guid employeeId, string fcmToken, Guid tenentId)
|
public async Task SendLoginOnAnotherDeviceMessageAsync(Guid employeeId, string fcmToken, Guid tenantId)
|
||||||
{
|
{
|
||||||
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ namespace Marco.Pms.Services.Service
|
|||||||
.Where(ft => ft.EmployeeId == employeeId &&
|
.Where(ft => ft.EmployeeId == employeeId &&
|
||||||
ft.ExpiredAt >= DateTime.UtcNow &&
|
ft.ExpiredAt >= DateTime.UtcNow &&
|
||||||
ft.FcmToken != fcmToken &&
|
ft.FcmToken != fcmToken &&
|
||||||
ft.TenantId == tenentId)
|
ft.TenantId == tenantId)
|
||||||
.Select(ft => ft.FcmToken).ToListAsync();
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
var notificationFirebase = new Notification
|
var notificationFirebase = new Notification
|
||||||
@ -52,14 +52,14 @@ namespace Marco.Pms.Services.Service
|
|||||||
|
|
||||||
await SendMessageToMultipleDevicesAsync(registrationTokens, notificationFirebase);
|
await SendMessageToMultipleDevicesAsync(registrationTokens, notificationFirebase);
|
||||||
}
|
}
|
||||||
public async Task SendLoginMessageAsync(string name, Guid tenentId)
|
public async Task SendLoginMessageAsync(string name, Guid tenantId)
|
||||||
{
|
{
|
||||||
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
// List of device registration tokens to send the message to
|
// List of device registration tokens to send the message to
|
||||||
var registrationTokens = await _context.FCMTokenMappings
|
var registrationTokens = await _context.FCMTokenMappings
|
||||||
.Where(ft => ft.ExpiredAt >= DateTime.UtcNow &&
|
.Where(ft => ft.ExpiredAt >= DateTime.UtcNow &&
|
||||||
ft.TenantId == tenentId)
|
ft.TenantId == tenantId)
|
||||||
.Select(ft => ft.FcmToken).ToListAsync();
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
var notificationFirebase = new Notification
|
var notificationFirebase = new Notification
|
||||||
@ -71,6 +71,32 @@ namespace Marco.Pms.Services.Service
|
|||||||
await SendMessageToMultipleDevicesAsync(registrationTokens, notificationFirebase);
|
await SendMessageToMultipleDevicesAsync(registrationTokens, notificationFirebase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Employee Controller
|
||||||
|
public async Task SendEmployeeSuspendMessageAsync(Guid employeeId, Guid tenantId)
|
||||||
|
{
|
||||||
|
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
|
var projectIds = await _context.ProjectAllocations
|
||||||
|
.Where(pa => pa.EmployeeId == employeeId && pa.TenantId == tenantId)
|
||||||
|
.Select(pa => pa.ProjectId).ToListAsync();
|
||||||
|
|
||||||
|
var employeeIds = await _context.ProjectAllocations
|
||||||
|
.Where(pa => projectIds.Contains(pa.ProjectId) && pa.TenantId == tenantId)
|
||||||
|
.Select(pa => pa.EmployeeId).ToListAsync();
|
||||||
|
|
||||||
|
var registrationTokensForData = await _context.FCMTokenMappings
|
||||||
|
.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
|
var data = new Dictionary<string, string>()
|
||||||
|
{
|
||||||
|
{ "Keyword", "Employee_Suspend" },
|
||||||
|
{ "EmployeeId", employeeId.ToString() }
|
||||||
|
};
|
||||||
|
|
||||||
|
await SendMessageToMultipleDevicesOnlyDataAsync(registrationTokensForData, data);
|
||||||
|
}
|
||||||
|
|
||||||
// Attendance Controller
|
// Attendance Controller
|
||||||
public async Task SendAttendanceMessageAsync(Guid projectId, string name, ATTENDANCE_MARK_TYPE markType, Guid employeeId, Guid tenantId)
|
public async Task SendAttendanceMessageAsync(Guid projectId, string name, ATTENDANCE_MARK_TYPE markType, Guid employeeId, Guid tenantId)
|
||||||
{
|
{
|
||||||
@ -213,7 +239,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
if (mesaageNotificationIds.Any())
|
if (mesaageNotificationIds.Any())
|
||||||
{
|
{
|
||||||
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||||
var registrationTokensForNotification = await dbContext.FCMTokenMappings.Where(ft => mesaageNotificationIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForNotification = await dbContext.FCMTokenMappings
|
||||||
|
.Where(ft => mesaageNotificationIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notificationFirebase, data);
|
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notificationFirebase, data);
|
||||||
}
|
}
|
||||||
@ -223,7 +251,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
if (teamEmployeeIds.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 => teamEmployeeIds.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 && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesOnlyDataAsync(registrationTokensForData, data);
|
await SendMessageToMultipleDevicesOnlyDataAsync(registrationTokensForData, data);
|
||||||
}
|
}
|
||||||
@ -316,7 +346,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
var registrationTokensForNotificationTask = Task.Run(async () =>
|
var registrationTokensForNotificationTask = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||||
var registrationTokensForNotification = await dbContext.FCMTokenMappings.Where(ft => teamMembers.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForNotification = await dbContext.FCMTokenMappings
|
||||||
|
.Where(ft => teamMembers.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
var notificationFirebase = new Notification
|
var notificationFirebase = new Notification
|
||||||
{
|
{
|
||||||
Title = $"Task Assigned for {project?.ProjectName}",
|
Title = $"Task Assigned for {project?.ProjectName}",
|
||||||
@ -328,7 +360,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
var registrationTokensForDataTask = Task.Run(async () =>
|
var registrationTokensForDataTask = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||||
var registrationTokensForData = await dbContext.FCMTokenMappings.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForData = await dbContext.FCMTokenMappings
|
||||||
|
.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesOnlyDataAsync(registrationTokensForData, data);
|
await SendMessageToMultipleDevicesOnlyDataAsync(registrationTokensForData, data);
|
||||||
});
|
});
|
||||||
@ -467,7 +501,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
var registrationTokensForNotificationTask = Task.Run(async () =>
|
var registrationTokensForNotificationTask = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||||
var registrationTokensForNotification = await dbContext.FCMTokenMappings.Where(ft => mesaageNotificationIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForNotification = await dbContext.FCMTokenMappings
|
||||||
|
.Where(ft => mesaageNotificationIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
var notificationFirebase = new Notification
|
var notificationFirebase = new Notification
|
||||||
{
|
{
|
||||||
Title = $"New Task Reported - {project?.ProjectName}",
|
Title = $"New Task Reported - {project?.ProjectName}",
|
||||||
@ -479,7 +515,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
var registrationTokensForDataTask = Task.Run(async () =>
|
var registrationTokensForDataTask = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
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 => dataNotificationIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesOnlyDataAsync(registrationTokensForData, data);
|
await SendMessageToMultipleDevicesOnlyDataAsync(registrationTokensForData, data);
|
||||||
});
|
});
|
||||||
@ -578,7 +616,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
|
|
||||||
|
|
||||||
// List of device registration tokens to send the message to
|
// List of device registration tokens to send the message to
|
||||||
var registrationTokensForNotification = await _context.FCMTokenMappings.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForNotification = await _context.FCMTokenMappings
|
||||||
|
.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
var notificationFirebase = new Notification
|
var notificationFirebase = new Notification
|
||||||
{
|
{
|
||||||
Title = $"New Comment on Task - {project?.ProjectName}",
|
Title = $"New Comment on Task - {project?.ProjectName}",
|
||||||
@ -692,7 +732,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
var registrationTokensForNotificationTask = Task.Run(async () =>
|
var registrationTokensForNotificationTask = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||||
var registrationTokensForNotification = await dbContext.FCMTokenMappings.Where(ft => teamMembers.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForNotification = await dbContext.FCMTokenMappings
|
||||||
|
.Where(ft => teamMembers.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
var notificationFirebase = new Notification
|
var notificationFirebase = new Notification
|
||||||
{
|
{
|
||||||
Title = $"Task Approved - {project?.ProjectName}",
|
Title = $"Task Approved - {project?.ProjectName}",
|
||||||
@ -704,7 +746,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
var registrationTokensForDataTask = Task.Run(async () =>
|
var registrationTokensForDataTask = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||||
var registrationTokensForData = await dbContext.FCMTokenMappings.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForData = await dbContext.FCMTokenMappings
|
||||||
|
.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesOnlyDataAsync(registrationTokensForData, data);
|
await SendMessageToMultipleDevicesOnlyDataAsync(registrationTokensForData, data);
|
||||||
});
|
});
|
||||||
@ -845,7 +889,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
|
|
||||||
|
|
||||||
// List of device registration tokens to send the message to
|
// List of device registration tokens to send the message to
|
||||||
var registrationTokensForNotification = await _context.FCMTokenMappings.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForNotification = await _context.FCMTokenMappings
|
||||||
|
.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notificationFirebase, data);
|
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notificationFirebase, data);
|
||||||
}
|
}
|
||||||
@ -960,7 +1006,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
|
|
||||||
|
|
||||||
// List of device registration tokens to send the message to
|
// List of device registration tokens to send the message to
|
||||||
var registrationTokensForNotification = await _context.FCMTokenMappings.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForNotification = await _context.FCMTokenMappings
|
||||||
|
.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notificationFirebase, data);
|
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notificationFirebase, data);
|
||||||
}
|
}
|
||||||
@ -1068,7 +1116,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
|
|
||||||
|
|
||||||
// List of device registration tokens to send the message to
|
// List of device registration tokens to send the message to
|
||||||
var registrationTokensForNotification = await _context.FCMTokenMappings.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForNotification = await _context.FCMTokenMappings
|
||||||
|
.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notificationFirebase, data);
|
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notificationFirebase, data);
|
||||||
}
|
}
|
||||||
@ -1170,7 +1220,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
|
|
||||||
|
|
||||||
// List of device registration tokens to send the message to
|
// List of device registration tokens to send the message to
|
||||||
var registrationTokensForNotification = await _context.FCMTokenMappings.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForNotification = await _context.FCMTokenMappings
|
||||||
|
.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notificationFirebase, data);
|
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notificationFirebase, data);
|
||||||
}
|
}
|
||||||
@ -1292,7 +1344,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
|
|
||||||
|
|
||||||
// List of device registration tokens to send the message to
|
// List of device registration tokens to send the message to
|
||||||
var registrationTokensForNotification = await _context.FCMTokenMappings.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForNotification = await _context.FCMTokenMappings
|
||||||
|
.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notificationFirebase, data);
|
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notificationFirebase, data);
|
||||||
}
|
}
|
||||||
@ -1390,14 +1444,18 @@ namespace Marco.Pms.Services.Service
|
|||||||
var registrationTokensForNotificationTask = Task.Run(async () =>
|
var registrationTokensForNotificationTask = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||||
var registrationTokensForNotification = await dbContext.FCMTokenMappings.Where(ft => projectAllocation.EmployeeId == ft.EmployeeId && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForNotification = await dbContext.FCMTokenMappings
|
||||||
|
.Where(ft => projectAllocation.EmployeeId == ft.EmployeeId && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notificationFirebase, data);
|
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notificationFirebase, data);
|
||||||
});
|
});
|
||||||
var registrationTokensForDataTask = Task.Run(async () =>
|
var registrationTokensForDataTask = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||||
var registrationTokensForData = await dbContext.FCMTokenMappings.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForData = await dbContext.FCMTokenMappings
|
||||||
|
.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesOnlyDataAsync(registrationTokensForData, data);
|
await SendMessageToMultipleDevicesOnlyDataAsync(registrationTokensForData, data);
|
||||||
});
|
});
|
||||||
@ -1481,7 +1539,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
};
|
};
|
||||||
|
|
||||||
// List of device registration tokens to send the message to
|
// List of device registration tokens to send the message to
|
||||||
var registrationTokensForNotification = await _context.FCMTokenMappings.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForNotification = await _context.FCMTokenMappings
|
||||||
|
.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notificationFirebase, data);
|
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notificationFirebase, data);
|
||||||
}
|
}
|
||||||
@ -1603,7 +1663,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
if (notificationFirebase != null)
|
if (notificationFirebase != null)
|
||||||
{
|
{
|
||||||
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||||
var registrationTokensForNotification = await dbContext.FCMTokenMappings.Where(ft => notificationEmployeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForNotification = await dbContext.FCMTokenMappings
|
||||||
|
.Where(ft => notificationEmployeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notificationFirebase, data);
|
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notificationFirebase, data);
|
||||||
}
|
}
|
||||||
@ -1612,7 +1674,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
{
|
{
|
||||||
|
|
||||||
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||||
var registrationTokensForNotification = await dbContext.FCMTokenMappings.Where(ft => dataEmployeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForNotification = await dbContext.FCMTokenMappings
|
||||||
|
.Where(ft => dataEmployeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesOnlyDataAsync(registrationTokensForNotification, data);
|
await SendMessageToMultipleDevicesOnlyDataAsync(registrationTokensForNotification, data);
|
||||||
|
|
||||||
@ -1622,7 +1686,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
if (notificationCreatedBy != null)
|
if (notificationCreatedBy != null)
|
||||||
{
|
{
|
||||||
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||||
var registrationTokensForemployee = await dbContext.FCMTokenMappings.Where(ft => ft.EmployeeId == expenses.CreatedById && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForemployee = await dbContext.FCMTokenMappings
|
||||||
|
.Where(ft => ft.EmployeeId == expenses.CreatedById && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForemployee, notificationCreatedBy, data);
|
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForemployee, notificationCreatedBy, data);
|
||||||
}
|
}
|
||||||
@ -1677,7 +1743,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
{ "ContactId", contactId.ToString() }
|
{ "ContactId", contactId.ToString() }
|
||||||
};
|
};
|
||||||
|
|
||||||
var registrationTokensForNotification = await _context.FCMTokenMappings.Where(ft => assignedEmployeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForNotification = await _context.FCMTokenMappings
|
||||||
|
.Where(ft => assignedEmployeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notification, data);
|
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notification, data);
|
||||||
}
|
}
|
||||||
@ -1721,7 +1789,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
{ "ContactId", contactId.ToString() }
|
{ "ContactId", contactId.ToString() }
|
||||||
};
|
};
|
||||||
|
|
||||||
var registrationTokensForNotification = await _context.FCMTokenMappings.Where(ft => assignedEmployeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForNotification = await _context.FCMTokenMappings
|
||||||
|
.Where(ft => assignedEmployeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notification, data);
|
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notification, data);
|
||||||
}
|
}
|
||||||
@ -1765,7 +1835,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
{"BucketId", bucketId.ToString() }
|
{"BucketId", bucketId.ToString() }
|
||||||
};
|
};
|
||||||
|
|
||||||
var registrationTokensForNotification = await _context.FCMTokenMappings.Where(ft => assignedEmployeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForNotification = await _context.FCMTokenMappings
|
||||||
|
.Where(ft => assignedEmployeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notification, data);
|
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notification, data);
|
||||||
}
|
}
|
||||||
@ -1780,7 +1852,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
{ "Keyword", "Bucket_Assigned" }
|
{ "Keyword", "Bucket_Assigned" }
|
||||||
};
|
};
|
||||||
|
|
||||||
var registrationTokensForNotification = await _context.FCMTokenMappings.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForNotification = await _context.FCMTokenMappings
|
||||||
|
.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notification, data);
|
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notification, data);
|
||||||
}
|
}
|
||||||
@ -1809,7 +1883,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
{ "DocumentId", documentId.ToString() }
|
{ "DocumentId", documentId.ToString() }
|
||||||
};
|
};
|
||||||
|
|
||||||
var registrationTokensForNotification = await _context.FCMTokenMappings.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForNotification = await _context.FCMTokenMappings
|
||||||
|
.Where(ft => employeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notification, data);
|
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notification, data);
|
||||||
}
|
}
|
||||||
@ -1878,7 +1954,9 @@ namespace Marco.Pms.Services.Service
|
|||||||
{ "DocumentId", documentId.ToString() }
|
{ "DocumentId", documentId.ToString() }
|
||||||
};
|
};
|
||||||
|
|
||||||
var registrationTokensForNotification = await _context.FCMTokenMappings.Where(ft => finalEmployeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow).Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokensForNotification = await _context.FCMTokenMappings
|
||||||
|
.Where(ft => finalEmployeeIds.Contains(ft.EmployeeId) && ft.ExpiredAt >= DateTime.UtcNow && ft.TenantId == tenantId)
|
||||||
|
.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notification, data);
|
await SendMessageToMultipleDevicesWithDataAsync(registrationTokensForNotification, notification, data);
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,9 @@ namespace Marco.Pms.Services.Service.ServiceInterfaces
|
|||||||
{
|
{
|
||||||
Task SendLoginMessageAsync(string name, Guid tenentId);
|
Task SendLoginMessageAsync(string name, Guid tenentId);
|
||||||
Task SendLoginOnAnotherDeviceMessageAsync(Guid employeeId, string fcmToken, Guid tenentId);
|
Task SendLoginOnAnotherDeviceMessageAsync(Guid employeeId, string fcmToken, Guid tenentId);
|
||||||
|
|
||||||
|
Task SendEmployeeSuspendMessageAsync(Guid employeeId, Guid tenantId);
|
||||||
|
|
||||||
Task SendAttendanceMessageAsync(Guid projectId, string Name, ATTENDANCE_MARK_TYPE markType, Guid employeeId, Guid tenantId);
|
Task SendAttendanceMessageAsync(Guid projectId, string Name, ATTENDANCE_MARK_TYPE markType, Guid employeeId, Guid tenantId);
|
||||||
Task SendAssignTaskMessageAsync(Guid workItemId, string name, List<Guid> teamMembers, Guid tenantId);
|
Task SendAssignTaskMessageAsync(Guid workItemId, string name, List<Guid> teamMembers, Guid tenantId);
|
||||||
Task SendReportTaskMessageAsync(Guid taskAllocationId, string name, Guid tenantId);
|
Task SendReportTaskMessageAsync(Guid taskAllocationId, string name, Guid tenantId);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user