Implemented an API to update Contact Category Master #69
Collaborator
- Get Tenant and Employee Info:
- Get the current tenant ID using _userHelper.GetTenantId().
- Get the currently logged-in employee with _userHelper.GetCurrentEmployeeAsync().
- Input Validation:
- Check that contactCategoryDto is not null and that its Id matches the provided id from the route.
- If this check fails:
- Log a warning that an empty or invalid payload was received.
- Return a 400 Bad Request error response: "User Send empty Payload".
- Fetch Category from Database:
- Try to find a ContactCategoryMaster entry that matches:
- The provided id
- The current tenant's ID
- If not found:
- Log a warning that the category does not exist.
- Return a 404 Not Found error response: "Category not found".
- Try to find a ContactCategoryMaster entry that matches:
- Update the Category:
- If the category is found:
- Update its Name and Description with values from contactCategoryDto, using empty strings if they are null.
- If the category is found:
- Log the Update:
- Add an entry to the DirectoryUpdateLogs table with:
- RefereanceId as the category ID
- UpdatedById as the employee ID
- UpdateAt as the current UTC time
- Save Changes:
- Persist all changes to the database using SaveChangesAsync().
- Build and Return Response:
- Convert the updated category to a ContactCategoryVM.
- Log an info mssage indicating the update with employee and category IDs.
- Return a 200 OK success response with the updated category data.
- **Get Tenant and Employee Info**:
- Get the current tenant ID using _userHelper.GetTenantId().
- Get the currently logged-in employee with _userHelper.GetCurrentEmployeeAsync().
- **Input Validation**:
- Check that contactCategoryDto is not null and that its Id matches the provided id from the route.
- If this check fails:
- Log a warning that an empty or invalid payload was received.
- Return a 400 Bad Request error response: "User Send empty Payload".
- **Fetch Category from Database**:
- Try to find a ContactCategoryMaster entry that matches:
- The provided id
- The current tenant's ID
- If not found:
- Log a warning that the category does not exist.
- Return a 404 Not Found error response: "Category not found".
- **Update the Category**:
- If the category is found:
- Update its Name and Description with values from contactCategoryDto, using empty strings if they are null.
- **Log the Update**:
- Add an entry to the DirectoryUpdateLogs table with:
- RefereanceId as the category ID
- UpdatedById as the employee ID
- UpdateAt as the current UTC time
- **Save Changes**:
- Persist all changes to the database using SaveChangesAsync().
- **Build and Return Response**:
- Convert the updated category to a ContactCategoryVM.
- Log an info mssage indicating the update with employee and category IDs.
- Return a 200 OK success response with the updated category data.
ashutosh.nehete
added 1 commit 2025-05-22 14:57:42 +00:00
Merge pull request 'Implemented an API to update Contact Category Master' (#69) from Ashutosh_Task#233_Update_Contact_Category into Feature_Directory
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "Ashutosh_Task#233_Update_Contact_Category"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?