Added updatelogs in delete contact API
This commit is contained in:
parent
6688b76145
commit
e7302ecd6c
@ -246,6 +246,7 @@ namespace Marco.Pms.Services.MappingProfiles
|
|||||||
|
|
||||||
CreateMap<Contact, ContactVM>();
|
CreateMap<Contact, ContactVM>();
|
||||||
CreateMap<CreateContactDto, Contact>();
|
CreateMap<CreateContactDto, Contact>();
|
||||||
|
CreateMap<UpdateContactDto, Contact>();
|
||||||
CreateMap<Contact, ContactProfileVM>();
|
CreateMap<Contact, ContactProfileVM>();
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,6 +34,8 @@ namespace Marco.Pms.Services.Service
|
|||||||
private static readonly string contactCollection = "ContactModificationLog";
|
private static readonly string contactCollection = "ContactModificationLog";
|
||||||
private static readonly string contactPhoneCollection = "ContactPhoneModificationLog";
|
private static readonly string contactPhoneCollection = "ContactPhoneModificationLog";
|
||||||
private static readonly string contactEmailCollection = "ContactEmailModificationLog";
|
private static readonly string contactEmailCollection = "ContactEmailModificationLog";
|
||||||
|
private static readonly string bucketCollection = "BucketModificationLog";
|
||||||
|
private static readonly string contactNoteCollection = "ContactNoteModificationLog";
|
||||||
|
|
||||||
|
|
||||||
public DirectoryService(
|
public DirectoryService(
|
||||||
@ -987,7 +989,10 @@ namespace Marco.Pms.Services.Service
|
|||||||
var accessibleBucketIds = contactBuckets.Select(cb => cb.BucketId).Distinct().ToHashSet();
|
var accessibleBucketIds = contactBuckets.Select(cb => cb.BucketId).Distinct().ToHashSet();
|
||||||
|
|
||||||
// Update the main contact object from DTO
|
// 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.UpdatedById = loggedInEmployee.Id;
|
||||||
updatedContact.UpdatedAt = DateTime.UtcNow;
|
updatedContact.UpdatedAt = DateTime.UtcNow;
|
||||||
|
|
||||||
@ -1372,6 +1377,8 @@ namespace Marco.Pms.Services.Service
|
|||||||
return ApiResponse<object>.ErrorResponse("Contact not found", "Contact not found", 404);
|
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)
|
// Update the contact's active status (soft delete or activate)
|
||||||
contact.IsActive = active;
|
contact.IsActive = active;
|
||||||
|
|
||||||
@ -1382,10 +1389,17 @@ namespace Marco.Pms.Services.Service
|
|||||||
UpdatedById = loggedInEmployee.Id,
|
UpdatedById = loggedInEmployee.Id,
|
||||||
UpdateAt = DateTime.UtcNow
|
UpdateAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
|
|
||||||
// Save changes to the database
|
// Save changes to the database
|
||||||
await _context.SaveChangesAsync();
|
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);
|
_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);
|
return ApiResponse<object>.SuccessResponse(new { }, active ? "Contact is activated successfully" : "Contact is deleted successfully", 200);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user