Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        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);
        }