public IHttpActionResult ApproveOrRejectExpense(ExpenseApprovalRequest request) { if (!ModelState.IsValid) { return(BadRequest()); } var response = ExpenseActionHandlers.ApproveOrRejectExpense(request); if (response.ApprovalStatus == (int)ApprovalStatusEnum.Unknown) { return(NotFound()); } return(Ok(response)); }
private static void RejectExpense(ExpenseApprovalRequest request, ExpenseAppEntities entity, ApprovalExpenseResponse response) { var expenseToBeRejected = (from expense in entity.Expenses where expense.ID == request.ExpenseId select expense).FirstOrDefault(); if (expenseToBeRejected == null) { response.IsSuccess = false; return; } expenseToBeRejected.LastExpenseActionId = (int)StatusEnum.Rejected; entity.SaveChanges(); response.ApprovalStatus = (int)ApprovalStatusEnum.Rejected; response.IsSuccess = true; }
public static ApprovalExpenseResponse ApproveOrRejectExpense(ExpenseApprovalRequest request) { ExpenseAppEntities entity = new ExpenseAppEntities(); ApprovalExpenseResponse response = new ApprovalExpenseResponse(); try { //to do:switch if (request.IsApproved) { ApproveExpense(request, entity, response); ExpenseHandlers.CreateExpenseHistory(request.ExpenseId, entity, request.RejectReason); return(response); } else if (!request.IsApproved) { RejectExpense(request, entity, response); ExpenseHandlers.CreateExpenseHistory(request.ExpenseId, entity, request.RejectReason); return(response); } else { response.ApprovalStatus = (int)ApprovalStatusEnum.Unknown; response.IsSuccess = false; return(response); } } catch (Exception ex) { response.IsSuccess = false; log.Error("Approve or Reject Expense Unsuccessful", ex); } finally { entity.Dispose(); } return(response); }