From e7302ecd6c50a9a5ba92a839e7c270d6edef9ea2 Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Mon, 11 Aug 2025 14:40:49 +0530 Subject: [PATCH] Added updatelogs in delete contact API --- .../MappingProfiles/MappingProfile.cs | 1 + Marco.Pms.Services/Service/DirectoryService.cs | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Marco.Pms.Services/MappingProfiles/MappingProfile.cs b/Marco.Pms.Services/MappingProfiles/MappingProfile.cs index 6eec11b..a4d0c55 100644 --- a/Marco.Pms.Services/MappingProfiles/MappingProfile.cs +++ b/Marco.Pms.Services/MappingProfiles/MappingProfile.cs @@ -246,6 +246,7 @@ namespace Marco.Pms.Services.MappingProfiles CreateMap(); CreateMap(); + CreateMap(); CreateMap(); diff --git a/Marco.Pms.Services/Service/DirectoryService.cs b/Marco.Pms.Services/Service/DirectoryService.cs index 3aa847b..c697fd2 100644 --- a/Marco.Pms.Services/Service/DirectoryService.cs +++ b/Marco.Pms.Services/Service/DirectoryService.cs @@ -34,6 +34,8 @@ namespace Marco.Pms.Services.Service private static readonly string contactCollection = "ContactModificationLog"; private static readonly string contactPhoneCollection = "ContactPhoneModificationLog"; private static readonly string contactEmailCollection = "ContactEmailModificationLog"; + private static readonly string bucketCollection = "BucketModificationLog"; + private static readonly string contactNoteCollection = "ContactNoteModificationLog"; public DirectoryService( @@ -987,7 +989,10 @@ namespace Marco.Pms.Services.Service var accessibleBucketIds = contactBuckets.Select(cb => cb.BucketId).Distinct().ToHashSet(); // Update the main contact object from DTO - var updatedContact = updateContact.ToContactFromUpdateContactDto(tenantId, contact); + var updatedContact = _mapper.Map(updateContact); + updatedContact.TenantId = tenantId; + updatedContact.CreatedAt = contact.CreatedAt; + updatedContact.CreatedById = contact.CreatedById; updatedContact.UpdatedById = loggedInEmployee.Id; updatedContact.UpdatedAt = DateTime.UtcNow; @@ -1372,6 +1377,8 @@ namespace Marco.Pms.Services.Service return ApiResponse.ErrorResponse("Contact not found", "Contact not found", 404); } + var contactObject = _updateLogsHelper.EntityToBsonDocument(contact); + // Update the contact's active status (soft delete or activate) contact.IsActive = active; @@ -1382,10 +1389,17 @@ namespace Marco.Pms.Services.Service UpdatedById = loggedInEmployee.Id, UpdateAt = DateTime.UtcNow }); - // Save changes to the database await _context.SaveChangesAsync(); + await _updateLogsHelper.PushToUpdateLogsAsync(new UpdateLogsObject + { + EntityId = contact.Id.ToString(), + UpdatedById = loggedInEmployee.Id.ToString(), + OldObject = contactObject, + UpdatedAt = DateTime.UtcNow + }, contactCollection); + _logger.LogInfo("Contact ID {ContactId} has been {(DeletedOrActivated)} by Employee ID {EmployeeId}.", id, active ? "activated" : "deleted", loggedInEmployee.Id); return ApiResponse.SuccessResponse(new { }, active ? "Contact is activated successfully" : "Contact is deleted successfully", 200);