From b17d1d30e5d764e2019439efe8cddad57eb8faae Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Mon, 15 Sep 2025 17:01:29 +0530 Subject: [PATCH] taken the requried service from thread --- .../Controllers/DocumentController.cs | 12 +++++++---- .../Service/DirectoryService.cs | 21 +++++++++---------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Marco.Pms.Services/Controllers/DocumentController.cs b/Marco.Pms.Services/Controllers/DocumentController.cs index 036e075..f145e7b 100644 --- a/Marco.Pms.Services/Controllers/DocumentController.cs +++ b/Marco.Pms.Services/Controllers/DocumentController.cs @@ -843,12 +843,13 @@ namespace Marco.Pms.Services.Controllers response.ParentAttachmentId = versionMapping.ParentAttachmentId; response.Version = versionMapping.Version; + 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. - var _firebase = scope.ServiceProvider.GetRequiredService(); var name = $"{loggedInEmployee.FirstName} {loggedInEmployee.LastName}"; @@ -966,12 +967,13 @@ namespace Marco.Pms.Services.Controllers } _logger.LogInfo("Document verified successfully. DocumentId: {DocumentId}, VerifiedBy: {EmployeeId}", documentAttachment.Id, loggedInEmployee.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. - var _firebase = scope.ServiceProvider.GetRequiredService(); var name = $"{loggedInEmployee.FirstName} {loggedInEmployee.LastName}"; @@ -1356,12 +1358,13 @@ namespace Marco.Pms.Services.Controllers response.Version = newVersionMapping.Version; _logger.LogInfo("API completed successfully for AttachmentId: {AttachmentId}", newAttachment.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. - var _firebase = scope.ServiceProvider.GetRequiredService(); var name = $"{loggedInEmployee.FirstName} {loggedInEmployee.LastName}"; @@ -1471,12 +1474,13 @@ namespace Marco.Pms.Services.Controllers // Log the successful completion of the operation _logger.LogInfo("DocumentAttachment ID: {DocumentId} has been {Message} by employee ID: {EmployeeId}", id, message, loggedInEmployee.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. - var _firebase = scope.ServiceProvider.GetRequiredService(); var entityType = documentAttachment.DocumentType?.DocumentCategory?.EntityTypeId; var documentType = documentAttachment.DocumentType; diff --git a/Marco.Pms.Services/Service/DirectoryService.cs b/Marco.Pms.Services/Service/DirectoryService.cs index a672d75..45cdc80 100644 --- a/Marco.Pms.Services/Service/DirectoryService.cs +++ b/Marco.Pms.Services/Service/DirectoryService.cs @@ -1012,13 +1012,12 @@ namespace Marco.Pms.Services.Service contactVM.BucketIds = contactBucketMappings.Select(cb => cb.BucketId).ToList(); contactVM.ProjectIds = projectMappings.Select(cp => cp.ProjectId).ToList(); + 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. - var _firebase = scope.ServiceProvider.GetRequiredService(); - var name = $"{loggedInEmployee.FirstName} {loggedInEmployee.LastName}"; var notification = new Notification @@ -1479,13 +1478,13 @@ namespace Marco.Pms.Services.Service var contactVM = responseTask.Result; _logger.LogInfo("Contact {ContactId} successfully updated by employee {EmployeeId}.", contact.Id, loggedInEmployee.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. - var _firebase = scope.ServiceProvider.GetRequiredService(); if (contactVM.BucketIds?.Any() ?? false) { @@ -1562,13 +1561,13 @@ namespace Marco.Pms.Services.Service _logger.LogInfo("Contact ID {ContactId} has been {(DeletedOrActivated)} by Employee ID {EmployeeId}.", id, active ? "activated" : "deleted", loggedInEmployee.Id); using var scope = _serviceScopeFactory.CreateScope(); + 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. - var _firebase = scope.ServiceProvider.GetRequiredService(); if (bucketIds.Any()) { @@ -2059,13 +2058,13 @@ namespace Marco.Pms.Services.Service loggedInEmployee.Id, note.Id, contact.Id, tenantId); using var scope = _serviceScopeFactory.CreateScope(); + 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. - var _firebase = scope.ServiceProvider.GetRequiredService(); var name = $"{loggedInEmployee.FirstName} {loggedInEmployee.LastName}"; @@ -2191,13 +2190,13 @@ namespace Marco.Pms.Services.Service loggedInEmployee.Id, noteVM.Id, contact.Id, noteVM.UpdatedAt); using var scope = _serviceScopeFactory.CreateScope(); + 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. - var _firebase = scope.ServiceProvider.GetRequiredService(); var name = $"{loggedInEmployee.FirstName} {loggedInEmployee.LastName}"; @@ -2319,13 +2318,13 @@ namespace Marco.Pms.Services.Service } using var scope = _serviceScopeFactory.CreateScope(); + 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. - var _firebase = scope.ServiceProvider.GetRequiredService(); var name = $"{loggedInEmployee.FirstName} {loggedInEmployee.LastName}"; @@ -2543,13 +2542,13 @@ namespace Marco.Pms.Services.Service _logger.LogInfo("Employee {EmployeeId} successfully created bucket {BucketId}", loggedInEmployee.Id, newBucket.Id); using var scope = _serviceScopeFactory.CreateScope(); + 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. - var _firebase = scope.ServiceProvider.GetRequiredService(); var name = $"{loggedInEmployee.FirstName} {loggedInEmployee.LastName}"; @@ -2676,13 +2675,13 @@ namespace Marco.Pms.Services.Service _logger.LogInfo("Employee ID {LoggedInEmployeeId} successfully updated bucket ID {BucketId}.", loggedInEmployee.Id, bucket.Id); using var scope = _serviceScopeFactory.CreateScope(); + 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. - var _firebase = scope.ServiceProvider.GetRequiredService(); var name = $"{loggedInEmployee.FirstName} {loggedInEmployee.LastName}"; @@ -2860,13 +2859,13 @@ namespace Marco.Pms.Services.Service _logger.LogInfo("Employee {EmployeeId} removed {Count} employees from bucket {BucketId}.", loggedInEmployee.Id, removedEmployeesCount, bucketId); } using var scope = _serviceScopeFactory.CreateScope(); + 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. - var _firebase = scope.ServiceProvider.GetRequiredService(); var name = $"{loggedInEmployee.FirstName} {loggedInEmployee.LastName}"; @@ -3007,13 +3006,13 @@ namespace Marco.Pms.Services.Service }, bucketCollection); using var scope = _serviceScopeFactory.CreateScope(); + 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. - var _firebase = scope.ServiceProvider.GetRequiredService(); var name = $"{loggedInEmployee.FirstName} {loggedInEmployee.LastName}";