diff --git a/Marco.Pms.Services/Service/DirectoryService.cs b/Marco.Pms.Services/Service/DirectoryService.cs
index 9375cad..a672d75 100644
--- a/Marco.Pms.Services/Service/DirectoryService.cs
+++ b/Marco.Pms.Services/Service/DirectoryService.cs
@@ -1,4 +1,5 @@
using AutoMapper;
+using FirebaseAdmin.Messaging;
using Marco.Pms.DataAccess.Data;
using Marco.Pms.Helpers.Utility;
using Marco.Pms.Model.Directory;
@@ -119,15 +120,18 @@ namespace Marco.Pms.Services.Service
// --- Advanced Filtering from 'filter' parameter ---
ContactFilterDto? contactFilter = TryDeserializeContactFilter(filter);
- if (contactFilter?.BucketIds?.Any() ?? false)
+ if (contactFilter != null)
{
- // Note: Permission filtering is already applied. Here we further restrict by the user's filter choice.
- contactQuery = contactQuery.Where(c => dbContext.ContactBucketMappings.Any(cbm =>
- cbm.ContactId == c.Id && contactFilter.BucketIds.Contains(cbm.BucketId)));
- }
- if (contactFilter?.CategoryIds?.Any() ?? false)
- {
- contactQuery = contactQuery.Where(c => c.ContactCategoryId.HasValue && contactFilter.CategoryIds.Contains(c.ContactCategoryId.Value));
+ if (contactFilter.BucketIds?.Any() ?? false)
+ {
+ // Note: Permission filtering is already applied. Here we further restrict by the user's filter choice.
+ contactQuery = contactQuery.Where(c => dbContext.ContactBucketMappings.Any(cbm =>
+ cbm.ContactId == c.Id && contactFilter.BucketIds.Contains(cbm.BucketId)));
+ }
+ if (contactFilter.CategoryIds?.Any() ?? false)
+ {
+ contactQuery = contactQuery.Where(c => c.ContactCategoryId.HasValue && contactFilter.CategoryIds.Contains(c.ContactCategoryId.Value));
+ }
}
// --- Standard Filtering ---
@@ -935,6 +939,7 @@ namespace Marco.Pms.Services.Service
/// An ApiResponse containing the newly created contact's view model or an error.
public async Task> CreateContactAsync(CreateContactDto createContact, Guid tenantId, Employee loggedInEmployee)
{
+ using var scope = _serviceScopeFactory.CreateScope();
Guid loggedInEmployeeId = loggedInEmployee.Id;
if (string.IsNullOrWhiteSpace(createContact.Name) ||
@@ -1007,6 +1012,25 @@ namespace Marco.Pms.Services.Service
contactVM.BucketIds = contactBucketMappings.Select(cb => cb.BucketId).ToList();
contactVM.ProjectIds = projectMappings.Select(cp => cp.ProjectId).ToList();
+ _ = 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
+ {
+ Title = "New Contact Created",
+ Body = $"New Contact \"{contact.Name}\" is created by {name} in your bucket"
+ };
+
+ await _firebase.SendContactAsync(contactVM.BucketIds, notification, tenantId);
+
+ });
+
return ApiResponse