Ejemplo n.º 1
0
        public JsonResult UpdateWorkflow(int id, int state, int direction)
        {
            RevenueApprovalStatus workflowState = (RevenueApprovalStatus)state;

            if (!((AuthorizationProvider.CanReviewRevenue() && workflowState == RevenueApprovalStatus.Reviewed) ||
                  (AuthorizationProvider.CanApproveRevenue() && workflowState == RevenueApprovalStatus.Approved) ||
                  (AuthorizationProvider.CanFinalizeRevenue() && workflowState == RevenueApprovalStatus.Finalized)))
            {
                return(Forbidden());
            }

            try
            {
                var dataProvider = new ReservationRevenueProvider(_dbContext);
                RevenueApprovalStatus?nextState = null;
                if (direction > 0)
                {
                    nextState = dataProvider.MoveWorkflow(id, workflowState);
                }
                else
                {
                    nextState = dataProvider.BacktrackWorkflow(id, workflowState);
                }

                if (nextState != null)
                {
                    return(Json(nextState, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json("-1", JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                string message = string.Format("Change Reservation {0} workflow fails. {1}", id.ToString(), ex.Message + ex.StackTrace);
                return(InternalError(message, "-1", ex));
            }
        }