Added the try catch in update payment request API
This commit is contained in:
parent
61674d69da
commit
214cacf092
@ -1209,7 +1209,7 @@ namespace Marco.Pms.Services.Service
|
|||||||
pr.CreatedBy != null &&
|
pr.CreatedBy != null &&
|
||||||
pr.CreatedBy.JobRole != null);
|
pr.CreatedBy.JobRole != null);
|
||||||
|
|
||||||
if (hasViewSelfPermissionTask.Result)
|
if (hasViewSelfPermissionTask.Result && !hasViewAllPermissionTask.Result)
|
||||||
{
|
{
|
||||||
paymentRequestQuery = paymentRequestQuery.Where(pr => pr.CreatedById == loggedInEmployee.Id);
|
paymentRequestQuery = paymentRequestQuery.Where(pr => pr.CreatedById == loggedInEmployee.Id);
|
||||||
}
|
}
|
||||||
@ -1994,8 +1994,21 @@ namespace Marco.Pms.Services.Service
|
|||||||
|
|
||||||
paymentRequest.IsAdvancePayment = model.IsAdvancePayment;
|
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
|
// 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();
|
var newBillAttachments = model.BillAttachments.Where(ba => ba.DocumentId == null && ba.IsActive).ToList();
|
||||||
if (newBillAttachments.Any())
|
if (newBillAttachments.Any())
|
||||||
@ -2071,12 +2084,11 @@ namespace Marco.Pms.Services.Service
|
|||||||
|
|
||||||
// Prepare response view model with updated details
|
// Prepare response view model with updated details
|
||||||
var response = _mapper.Map<PaymentRequestVM>(paymentRequest);
|
var response = _mapper.Map<PaymentRequestVM>(paymentRequest);
|
||||||
response.PaymentRequestUID = $"{paymentRequest.UIDPrefix}/{paymentRequest.UIDPostfix:D5}";
|
response.PaymentRequestUID = paymentRequestUID;
|
||||||
response.Currency = currency;
|
response.Currency = currency;
|
||||||
response.ExpenseCategory = _mapper.Map<ExpensesCategoryMasterVM>(expenseCategory);
|
response.ExpenseCategory = _mapper.Map<ExpensesCategoryMasterVM>(expenseCategory);
|
||||||
response.Project = _mapper.Map<BasicProjectVM>(project);
|
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);
|
return ApiResponse<object>.SuccessResponse(response, "Payment Request updated successfully.", 200);
|
||||||
}
|
}
|
||||||
catch (ArgumentException ex)
|
catch (ArgumentException ex)
|
||||||
@ -2134,6 +2146,11 @@ namespace Marco.Pms.Services.Service
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region =================================================================== Recurring Payment Functions ===================================================================
|
#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
|
#endregion
|
||||||
|
|
||||||
#region =================================================================== Helper Functions ===================================================================
|
#region =================================================================== Helper Functions ===================================================================
|
||||||
|
|||||||
@ -33,6 +33,7 @@ namespace Marco.Pms.Services.Service.ServiceInterfaces
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region =================================================================== Recurring Payment Functions ===================================================================
|
#region =================================================================== Recurring Payment Functions ===================================================================
|
||||||
|
Task<ApiResponse<object>> CreateRecurringPaymentAsync(RecurringTemplateDto model, Employee loggedInEmployee, Guid tenantId);
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user