Directory_Refactor #128

Merged
ashutosh.nehete merged 22 commits from Directory_Refactor into Document_Manager 2025-09-09 11:03:46 +00:00
2 changed files with 17 additions and 2 deletions
Showing only changes of commit e7302ecd6c - Show all commits

View File

@ -246,6 +246,7 @@ namespace Marco.Pms.Services.MappingProfiles
CreateMap<Contact, ContactVM>();
CreateMap<CreateContactDto, Contact>();
CreateMap<UpdateContactDto, Contact>();
CreateMap<Contact, ContactProfileVM>();

View File

@ -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<Contact>(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<object>.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<object>.SuccessResponse(new { }, active ? "Contact is activated successfully" : "Contact is deleted successfully", 200);