// Replaced by stored precedure version MoveWorkflowAll above due to performance issue using Entity Framework for bulk db operation public RevenueApprovalStatus?BacktrackWorkflowAll(DateTime month, RevenueApprovalStatus state) { try { // Too slow to use Entity Framework for bulk upload var provider = new ResolutionRevenueProvider(_context); var resolutions = provider.Retrieve(month, string.Empty); var prevState = PrevState(state); if (resolutions != null && prevState != null) { var dataProvider = new ResolutionProvider(_context); foreach (var viewModel in resolutions) { //BacktrackWorkflow(viewModel.ResolutionId, state); var entity = dataProvider.Retrieve(viewModel.ResolutionId); if (entity != null) { entity.ApprovalStatus = prevState.Value; RetrackWorkflowSignature(entity, state); dataProvider.Update(entity.ResolutionId, entity); } } dataProvider.Commit(); return(prevState); } } catch { throw; } return(null); }
public JsonResult UpdateWorkflowAll(DateTime month, string propertyCode, 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 ExpenseRevenueProvider(_dbContext); var nextState = dataProvider.MoveWorkflowAll(month, propertyCode, workflowState, direction); if (nextState != null) { return(Json(nextState, JsonRequestBehavior.AllowGet)); } else { return(Json("-1", JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { string message = string.Format("Change {0} Expense workflow fails for property {1}. {2}", month.ToString("MM/dd/yyyy"), propertyCode, ex.Message + ex.StackTrace); return(InternalError(message, "-1", ex)); } }
public RevenueApprovalStatus?MoveWorkflowAll(DateTime month, RevenueApprovalStatus state, int direction) { try { // Stored procedure for bulk update is a lot faster var user = ClaimProvider.GetFriendlyName(_context); var nextState = direction >= 0 ? NextState(state) : PrevState(state); DateTime startDate = new DateTime(month.Year, month.Month, 1); DateTime endDate = new DateTime(month.Year, month.Month, DateTime.DaysInMonth(month.Year, month.Month)); SqlParameter[] sqlParams = new SqlParameter[4]; sqlParams[0] = new SqlParameter("@StartDate", SqlDbType.DateTime); sqlParams[0].Value = startDate; sqlParams[1] = new SqlParameter("@EndDate", SqlDbType.DateTime); sqlParams[1].Value = endDate; sqlParams[2] = new SqlParameter("@State", SqlDbType.Int); sqlParams[2].Value = direction >= 0 ? state : nextState; sqlParams[3] = new SqlParameter("@User", SqlDbType.NVarChar); sqlParams[3].Value = user; var result = _context.Database.SqlQuery <SqlResult>("UpdateAllResolutionWorkflowStates @StartDate, @EndDate, @State, @User", sqlParams).FirstOrDefault(); return(result.Count > 0 ? nextState : null); } catch { throw; } }
// Replaced by stored precedure version MoveWorkflowAll above due to performance issue using Entity Framework for bulk db operation public RevenueApprovalStatus?MoveWorkflowAll(DateTime month, RevenueApprovalStatus state) { try { // Too slow using Entity Framework for bulk upload var provider = new ResolutionRevenueProvider(_context); List <ResolutionRevenueModel> resolutions = provider.Retrieve(month, string.Empty); var nextState = NextState(state); if (resolutions != null && nextState != null) { var dataProvider = new ResolutionProvider(_context); foreach (var viewModel in resolutions) { //MoveWorkflow(viewModel.ResolutionId, state); var entity = dataProvider.Retrieve(viewModel.ResolutionId); if (entity != null) { entity.ApprovalStatus = state; SetWorkflowSignature(entity, state); dataProvider.Update(entity.ResolutionId, entity); } } dataProvider.Commit(); return(nextState); } } catch { throw; } return(null); }
private RevenueApprovalStatus?PrevState(RevenueApprovalStatus state) { var prevState = ((int)state - 1); if (prevState < (int)RevenueApprovalStatus.NotStarted) { return(null); } else { return((RevenueApprovalStatus)prevState); } }
private RevenueApprovalStatus?NextState(RevenueApprovalStatus state) { var nextState = ((int)state + 1); if (nextState > (int)RevenueApprovalStatus.Closed) { return(null); } else { return((RevenueApprovalStatus)nextState); } }
private void RetrackWorkflowSignature(Reservation reservation, RevenueApprovalStatus state) { var userName = ClaimProvider.GetFriendlyName(_context); switch (state) { case RevenueApprovalStatus.Reviewed: reservation.ReviewedBy = null; reservation.ReviewedDate = null; break; case RevenueApprovalStatus.Approved: reservation.ApprovedBy = null; reservation.ApprovedDate = null; break; } }
private void SetWorkflowSignature(Reservation reservation, RevenueApprovalStatus state) { var userName = ClaimProvider.GetFriendlyName(_context); switch (state) { case RevenueApprovalStatus.Reviewed: reservation.ReviewedBy = userName; reservation.ReviewedDate = DateTime.Now.ToUniversalTime(); break; case RevenueApprovalStatus.Approved: reservation.ApprovedBy = userName; reservation.ApprovedDate = DateTime.Now.ToUniversalTime(); break; } }
private void RetrackWorkflowSignature(Expense entity, RevenueApprovalStatus state) { var userName = ClaimProvider.GetFriendlyName(_context); switch (state) { case RevenueApprovalStatus.Reviewed: entity.ReviewedBy = null; entity.ReviewedDate = null; break; case RevenueApprovalStatus.Approved: entity.ApprovedBy = null; entity.ApprovedDate = null; break; } }
private void SetWorkflowSignature(ref OtherRevenue entity, RevenueApprovalStatus state) { var userName = ClaimProvider.GetFriendlyName(_context); switch (state) { case RevenueApprovalStatus.Reviewed: entity.ReviewedBy = userName; entity.ReviewedDate = DateTime.Now.ToUniversalTime(); break; case RevenueApprovalStatus.Approved: entity.ApprovedBy = userName; entity.ApprovedDate = DateTime.Now.ToUniversalTime(); break; } }
public JsonResult UpdateWorkflow(int id, int state, int direction) { if (!AuthorizationProvider.CanEditRevenue()) { return(Forbidden()); } 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 OtherRevenueProvider(_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 Other Expense {0} workflow fails. {1}", id.ToString(), ex.Message + ex.StackTrace); return(InternalError(message, "-1", ex)); } }
public RevenueApprovalStatus?MoveWorkflow(int reservationId, RevenueApprovalStatus state) { try { var reservationProvider = new ReservationProvider(_context); var reservation = reservationProvider.Retrieve(reservationId); var nextState = NextState(state); if (reservation != null && nextState != null) { reservation.ApprovalStatus = state; SetWorkflowSignature(reservation, state); reservationProvider.Update(reservationId, reservation); reservationProvider.Commit(); return(nextState); } } catch { throw; } return(null); }
public RevenueApprovalStatus?BacktrackWorkflow(int reservationId, RevenueApprovalStatus state) { try { var reservationProvider = new ReservationProvider(_context); var reservation = reservationProvider.Retrieve(reservationId); var prevState = PrevState(state); if (reservation != null && prevState != null) { reservation.ApprovalStatus = prevState.Value; RetrackWorkflowSignature(reservation, state); reservationProvider.Update(reservationId, reservation); reservationProvider.Commit(); return(prevState); } } catch { throw; } return(null); }
public RevenueApprovalStatus?BacktrackWorkflow(int expenseId, RevenueApprovalStatus state) { try { var dataProvider = new ExpenseProvider(_context); var entity = dataProvider.Retrieve(expenseId); var prevState = PrevState(state); if (entity != null && prevState != null) { entity.ApprovalStatus = prevState.Value; RetrackWorkflowSignature(entity, state); dataProvider.Update(expenseId, entity); dataProvider.Commit(); return(prevState); } } catch { throw; } return(null); }
public RevenueApprovalStatus?MoveWorkflow(int expenseId, RevenueApprovalStatus state) { try { var dataProvider = new ExpenseProvider(_context); var entity = dataProvider.Retrieve(expenseId); var nextState = NextState(state); if (entity != null && nextState != null) { entity.ApprovalStatus = state; SetWorkflowSignature(entity, state); dataProvider.Update(expenseId, entity); dataProvider.Commit(); return(nextState); } } catch { throw; } return(null); }
public RevenueApprovalStatus?BacktrackWorkflowAll(DateTime month, string propertyCode, RevenueApprovalStatus state) { try { var reservationProvider = new ReservationProvider(_context); DateTime startDate = new DateTime(month.Year, month.Month, 1); DateTime endDate = new DateTime(month.Year, month.Month, DateTime.DaysInMonth(month.Year, month.Month)); var reservations = reservationProvider.Retrieve(startDate, endDate, propertyCode); var prevState = PrevState(state); if (reservations != null && prevState != null) { foreach (var reservation in reservations) { if (reservation.ApprovalStatus >= prevState) { reservation.ApprovalStatus = prevState.Value; RetrackWorkflowSignature(reservation, state); reservationProvider.Update(reservation.ReservationId, reservation); } } reservationProvider.Commit(); return(prevState); } } catch { throw; } return(null); }
// Replaced by stored precedure version MoveWorkflowAll above due to performance issue using Entity Framework for bulk db operation public RevenueApprovalStatus?BacktrackWorkflowAll(DateTime month, string propertyCode, RevenueApprovalStatus state) { try { var provider = new ExpenseProvider(_context); DateTime startDate = new DateTime(month.Year, month.Month, 1); DateTime endDate = new DateTime(month.Year, month.Month, DateTime.DaysInMonth(month.Year, month.Month)); var expenses = provider.RetrieveCombinedExpenses(startDate, endDate, propertyCode); var prevState = PrevState(state); if (expenses != null && prevState != null) { foreach (var expense in expenses) { if (expense.ApprovalStatus >= prevState) { expense.ApprovalStatus = prevState.Value; RetrackWorkflowSignature(expense, state); provider.Update(expense.ExpenseId, expense); } } provider.Commit(); return(prevState); } } catch { throw; } return(null); }