Esempio n. 1
0
        public static BaseResponse SendExpenseForApproval(IdRequest request)
        {
            BaseResponse       response = new BaseResponse();
            ExpenseAppEntities entity   = new ExpenseAppEntities();

            try
            {
                var expenseToBeSentForApproval = (from expense in entity.Expenses
                                                  where expense.ID == request.ID
                                                  select expense).FirstOrDefault();
                if (expenseToBeSentForApproval == null)
                {
                    response.IsSuccess = false;
                    return(response);
                }

                expenseToBeSentForApproval.LastExpenseActionId = (int)StatusEnum.WaitingForManagerApproval;
                ExpenseHandlers.CreateExpenseHistory(request.ID, entity, null);
                response.IsSuccess = true;
                entity.SaveChanges();
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                log.Error("Send Expense For Approval Unsuccessful", ex);
            }
            finally
            {
                entity.Dispose();
            }
            return(response);
        }
Esempio n. 2
0
        public static BaseResponse PayExpense(IdRequest request)
        {
            BaseResponse       response = new BaseResponse();
            ExpenseAppEntities entity   = new ExpenseAppEntities();

            try
            {
                var expenseToBePaid = (from expense in entity.Expenses
                                       where expense.ID == request.ID
                                       select expense).FirstOrDefault();
                if (expenseToBePaid == null)
                {
                    response.IsSuccess = false;
                    return(response);
                }
                expenseToBePaid.LastExpenseActionId = (int)StatusEnum.Completed;
                ExpenseHandlers.CreateExpenseHistory(request.ID, entity, null);
                entity.SaveChanges();
                response.IsSuccess = true;
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                log.Error("Pay Expense", ex);
            }
            finally
            {
                entity.Dispose();
            }
            return(response);
        }
Esempio 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);
        }