Added the try catch in update payment request API

This commit is contained in:
ashutosh.nehete 2025-11-04 10:26:17 +05:30
parent 61674d69da
commit 214cacf092
2 changed files with 22 additions and 4 deletions

View File

@ -1209,7 +1209,7 @@ namespace Marco.Pms.Services.Service
pr.CreatedBy != null &&
pr.CreatedBy.JobRole != null);
if (hasViewSelfPermissionTask.Result)
if (hasViewSelfPermissionTask.Result && !hasViewAllPermissionTask.Result)
{
paymentRequestQuery = paymentRequestQuery.Where(pr => pr.CreatedById == loggedInEmployee.Id);
}
@ -1994,8 +1994,21 @@ namespace Marco.Pms.Services.Service
paymentRequest.IsAdvancePayment = model.IsAdvancePayment;
var paymentRequestUID = $"{paymentRequest.UIDPrefix}/{paymentRequest.UIDPostfix:D5}";
try
{
await _context.SaveChangesAsync();
_logger.LogInfo("PaymentRequest updated successfully with UID: {PaymentRequestUID}", paymentRequestUID);
}
catch (DbUpdateException dbEx)
{
_logger.LogError(dbEx, "Database Exception during Payment Request update");
return ApiResponse<object>.ErrorResponse("Database exception during payment request updation", ExceptionMapper(dbEx), 500);
}
// Handle bill attachment updates: add new attachments and delete deactivated ones
if (model.BillAttachments?.Any() == true)
if (model.BillAttachments?.Any() == true && !statusCheck)
{
var newBillAttachments = model.BillAttachments.Where(ba => ba.DocumentId == null && ba.IsActive).ToList();
if (newBillAttachments.Any())
@ -2071,12 +2084,11 @@ namespace Marco.Pms.Services.Service
// Prepare response view model with updated details
var response = _mapper.Map<PaymentRequestVM>(paymentRequest);
response.PaymentRequestUID = $"{paymentRequest.UIDPrefix}/{paymentRequest.UIDPostfix:D5}";
response.PaymentRequestUID = paymentRequestUID;
response.Currency = currency;
response.ExpenseCategory = _mapper.Map<ExpensesCategoryMasterVM>(expenseCategory);
response.Project = _mapper.Map<BasicProjectVM>(project);
_logger.LogInfo("PaymentRequest updated successfully with UID: {PaymentRequestUID}", response.PaymentRequestUID);
return ApiResponse<object>.SuccessResponse(response, "Payment Request updated successfully.", 200);
}
catch (ArgumentException ex)
@ -2134,6 +2146,11 @@ namespace Marco.Pms.Services.Service
#endregion
#region =================================================================== Recurring Payment Functions ===================================================================
public async Task<ApiResponse<object>> CreateRecurringPaymentAsync(RecurringTemplateDto model, Employee loggedInEmployee, Guid tenantId)
{
var recurringPayment = _mapper.Map<RecurringPayment>(model);
return ApiResponse<object>.SuccessResponse(recurringPayment, "Recurring Payment Template created successfully", 201);
}
#endregion
#region =================================================================== Helper Functions ===================================================================

View File

@ -33,6 +33,7 @@ namespace Marco.Pms.Services.Service.ServiceInterfaces
#endregion
#region =================================================================== Recurring Payment Functions ===================================================================
Task<ApiResponse<object>> CreateRecurringPaymentAsync(RecurringTemplateDto model, Employee loggedInEmployee, Guid tenantId);
#endregion
}
}