From eba1a700373065317af14a53f5912893a43314c9 Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Sat, 20 Sep 2025 11:12:32 +0530 Subject: [PATCH] Added the data notification in delete employee API --- .../Controllers/EmployeeController.cs | 33 ++++- Marco.Pms.Services/Service/FirebaseService.cs | 138 ++++++++++++++---- .../ServiceInterfaces/IFirebaseService.cs | 3 + 3 files changed, 141 insertions(+), 33 deletions(-) diff --git a/Marco.Pms.Services/Controllers/EmployeeController.cs b/Marco.Pms.Services/Controllers/EmployeeController.cs index 82a10fb..ae8c9a8 100644 --- a/Marco.Pms.Services/Controllers/EmployeeController.cs +++ b/Marco.Pms.Services/Controllers/EmployeeController.cs @@ -33,6 +33,7 @@ namespace MarcoBMS.Services.Controllers { private readonly ApplicationDbContext _context; + private readonly IServiceScopeFactory _serviceScope; private readonly UserManager _userManager; private readonly IEmailSender _emailSender; private readonly EmployeeHelper _employeeHelper; @@ -47,10 +48,21 @@ namespace MarcoBMS.Services.Controllers private readonly Guid tenantId; - public EmployeeController(UserManager userManager, IEmailSender emailSender, - ApplicationDbContext context, EmployeeHelper employeeHelper, UserHelper userHelper, IConfiguration configuration, ILoggingService logger, - IHubContext signalR, PermissionServices permission, IProjectServices projectServices, IMapper mapper, GeneralHelper generalHelper) + public EmployeeController(IServiceScopeFactory serviceScope, + UserManager userManager, + IEmailSender emailSender, + ApplicationDbContext context, + EmployeeHelper employeeHelper, + UserHelper userHelper, + IConfiguration configuration, + ILoggingService logger, + IHubContext signalR, + PermissionServices permission, + IProjectServices projectServices, + IMapper mapper, + GeneralHelper generalHelper) { + _serviceScope = serviceScope; _context = context; _userManager = userManager; _emailSender = emailSender; @@ -519,6 +531,8 @@ namespace MarcoBMS.Services.Controllers [HttpDelete("{id}")] public async Task SuspendEmployee(Guid id, [FromQuery] bool active = false) { + using var scope = _serviceScope.CreateScope(); + Guid tenantId = _userHelper.GetTenantId(); var LoggedEmployee = await _userHelper.GetCurrentEmployeeAsync(); 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("Employee with ID {EmployeId} Deleted successfully", employee.Id); + + var _firebase = scope.ServiceProvider.GetRequiredService(); + + _ = 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 { diff --git a/Marco.Pms.Services/Service/FirebaseService.cs b/Marco.Pms.Services/Service/FirebaseService.cs index 79627a4..5cdf209 100644 --- a/Marco.Pms.Services/Service/FirebaseService.cs +++ b/Marco.Pms.Services/Service/FirebaseService.cs @@ -32,7 +32,7 @@ namespace Marco.Pms.Services.Service } // 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(); @@ -41,7 +41,7 @@ namespace Marco.Pms.Services.Service .Where(ft => ft.EmployeeId == employeeId && ft.ExpiredAt >= DateTime.UtcNow && ft.FcmToken != fcmToken && - ft.TenantId == tenentId) + ft.TenantId == tenantId) .Select(ft => ft.FcmToken).ToListAsync(); var notificationFirebase = new Notification @@ -52,14 +52,14 @@ namespace Marco.Pms.Services.Service 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(); // List of device registration tokens to send the message to var registrationTokens = await _context.FCMTokenMappings .Where(ft => ft.ExpiredAt >= DateTime.UtcNow && - ft.TenantId == tenentId) + ft.TenantId == tenantId) .Select(ft => ft.FcmToken).ToListAsync(); var notificationFirebase = new Notification @@ -71,6 +71,32 @@ namespace Marco.Pms.Services.Service 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() + { + { "Keyword", "Employee_Suspend" }, + { "EmployeeId", employeeId.ToString() } + }; + + await SendMessageToMultipleDevicesOnlyDataAsync(registrationTokensForData, data); + } + // Attendance Controller 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()) { 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); } @@ -223,7 +251,9 @@ namespace Marco.Pms.Services.Service if (teamEmployeeIds.Any()) { 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); } @@ -316,7 +346,9 @@ namespace Marco.Pms.Services.Service var registrationTokensForNotificationTask = Task.Run(async () => { 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 { Title = $"Task Assigned for {project?.ProjectName}", @@ -328,7 +360,9 @@ namespace Marco.Pms.Services.Service var registrationTokensForDataTask = Task.Run(async () => { 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); }); @@ -467,7 +501,9 @@ namespace Marco.Pms.Services.Service var registrationTokensForNotificationTask = Task.Run(async () => { 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 { Title = $"New Task Reported - {project?.ProjectName}", @@ -479,7 +515,9 @@ namespace Marco.Pms.Services.Service var registrationTokensForDataTask = Task.Run(async () => { 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); }); @@ -578,7 +616,9 @@ namespace Marco.Pms.Services.Service // 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 { Title = $"New Comment on Task - {project?.ProjectName}", @@ -692,7 +732,9 @@ namespace Marco.Pms.Services.Service var registrationTokensForNotificationTask = Task.Run(async () => { 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 { Title = $"Task Approved - {project?.ProjectName}", @@ -704,7 +746,9 @@ namespace Marco.Pms.Services.Service var registrationTokensForDataTask = Task.Run(async () => { 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); }); @@ -845,7 +889,9 @@ namespace Marco.Pms.Services.Service // 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); } @@ -960,7 +1006,9 @@ namespace Marco.Pms.Services.Service // 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); } @@ -1068,7 +1116,9 @@ namespace Marco.Pms.Services.Service // 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); } @@ -1170,7 +1220,9 @@ namespace Marco.Pms.Services.Service // 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); } @@ -1292,7 +1344,9 @@ namespace Marco.Pms.Services.Service // 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); } @@ -1390,14 +1444,18 @@ namespace Marco.Pms.Services.Service var registrationTokensForNotificationTask = Task.Run(async () => { 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); }); var registrationTokensForDataTask = Task.Run(async () => { 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); }); @@ -1481,7 +1539,9 @@ namespace Marco.Pms.Services.Service }; // 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); } @@ -1603,7 +1663,9 @@ namespace Marco.Pms.Services.Service if (notificationFirebase != null) { 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); } @@ -1612,7 +1674,9 @@ namespace Marco.Pms.Services.Service { 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); @@ -1622,7 +1686,9 @@ namespace Marco.Pms.Services.Service if (notificationCreatedBy != null) { 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); } @@ -1677,7 +1743,9 @@ namespace Marco.Pms.Services.Service { "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); } @@ -1721,7 +1789,9 @@ namespace Marco.Pms.Services.Service { "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); } @@ -1765,7 +1835,9 @@ namespace Marco.Pms.Services.Service {"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); } @@ -1780,7 +1852,9 @@ namespace Marco.Pms.Services.Service { "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); } @@ -1809,7 +1883,9 @@ namespace Marco.Pms.Services.Service { "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); } @@ -1878,7 +1954,9 @@ namespace Marco.Pms.Services.Service { "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); } diff --git a/Marco.Pms.Services/Service/ServiceInterfaces/IFirebaseService.cs b/Marco.Pms.Services/Service/ServiceInterfaces/IFirebaseService.cs index 5bc2360..53fc50d 100644 --- a/Marco.Pms.Services/Service/ServiceInterfaces/IFirebaseService.cs +++ b/Marco.Pms.Services/Service/ServiceInterfaces/IFirebaseService.cs @@ -9,6 +9,9 @@ namespace Marco.Pms.Services.Service.ServiceInterfaces { Task SendLoginMessageAsync(string name, 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 SendAssignTaskMessageAsync(Guid workItemId, string name, List teamMembers, Guid tenantId); Task SendReportTaskMessageAsync(Guid taskAllocationId, string name, Guid tenantId);