private List <PlanningAppState> RollbackDueByDates(int daysDiff, PlanningAppState current) { return(PlanningAppStates .Where(s => s.DueByDate > current.DueByDate) .Select(c => { c.DueByDate = c.DueByDate.AddBusinessDays(-daysDiff); return c; }) .ToList()); }
public void NextState(List <StateStatus> statusList) { if (!Completed()) { PlanningAppStates = PlanningAppStates.OrderBy(s => s.state.OrderId).ToList(); var currentDate = SystemDate.Instance.date; var prevState = Current(); //Store reference to current state if (!isLastState(prevState)) { SeekNext().CurrentState = true; //move to next state } prevState.CompleteState(currentDate, statusList); //Close out previouse state //If Overran then roll all future completion dates by business days overdue if (currentDate > prevState.DueByDate) { var daysDiff = prevState.DueByDate.GetBusinessDays(currentDate, new List <DateTime>()); RollForwardDueByDates(daysDiff, prevState); } } if (Completed()) { CurrentPlanningStatus = statusList.Where(s => s.Name == StatusList.Complete).SingleOrDefault(); } }
public void generateDueByDates() { if (!Completed()) { //Important - put states in order before processing!! PlanningAppStates = PlanningAppStates.OrderBy(s => s.state.OrderId).ToList(); var prevState = new PlanningAppState(); var currState = Current(); var resetCurrent = Current(); while (currState != null) { if (!isFirstState(currState)) { prevState = SeekPrev(); currState.AggregateDueByDate(prevState); } else { currState.SetDueByDate(); } currState = Next(currState); } //Set original state SetCurrent(resetCurrent); } }
public void SetCurrent(PlanningAppState planningAppState) { foreach (var state in PlanningAppStates) { state.CurrentState = false; } PlanningAppStates[PlanningAppStates.IndexOf(planningAppState)].CurrentState = true; }
private void RollForwardDueByDates(int daysDiff, PlanningAppState prevState) { if (!Completed()) { PlanningAppStates .Where(s => s.DueByDate > prevState.DueByDate) .Select(c => { c.DueByDate = c.DueByDate.AddBusinessDays(daysDiff); return(c); }) .ToList(); } }
public PlanningAppState SeekNext() { if (!Completed() && !isLastState(Current())) { return(PlanningAppStates[PlanningAppStates.IndexOf(Current()) + 1]); } else { return(null); } }
public PlanningAppState SeekPrev(PlanningAppState planningAppState) //Get previous state based on specified State { if (!Completed() && !isFirstState(planningAppState)) { return(PlanningAppStates[PlanningAppStates.IndexOf(planningAppState) - 1]); } else { return(null); } }
public PlanningAppState SeekPrev() //Get previous state based on CurrentState { if (!Completed() && !isFirstState(Current())) { return(PlanningAppStates[PlanningAppStates.IndexOf(Current()) - 1]); } else { return(null); } }
public PlanningAppState Next(PlanningAppState planningAppState) { PlanningAppState nextState = new PlanningAppState(); if (!isLastState(planningAppState)) { nextState = PlanningAppStates[PlanningAppStates.IndexOf(planningAppState) + 1]; planningAppState.CurrentState = false; nextState.CurrentState = true; return(nextState); } else { return(null); } }
public PlanningApp GeneratePlanningStates(List <StateInitialiserState> stateInitialisers, IEnumerable <StateStatus> stateStatus) { var currentDate = SystemDate.Instance.date; foreach (var stateInialiser in stateInitialisers) { PlanningAppState newPlanningAppState = new PlanningAppState(); newPlanningAppState.state = stateInialiser; PlanningAppState prevState; var stateCount = PlanningAppStates.Count; if (stateCount > 0) { prevState = PlanningAppStates[stateCount - 1]; newPlanningAppState.DueByDate = prevState.DueByDate.AddBusinessDays(stateInialiser.CompletionTime); } else { newPlanningAppState.DueByDate = currentDate.AddBusinessDays(stateInialiser.CompletionTime); } newPlanningAppState.StateStatus = stateStatus.Where(s => s.Name == StatusList.OnTime).SingleOrDefault(); //Add custom fields to state if exist foreach (var stateInitialiserStateCustomField in newPlanningAppState.state.StateInitialiserStateCustomFields) { newPlanningAppState.customFields .Add(new PlanningAppStateCustomField { StateInitialiserStateCustomFieldId = stateInitialiserStateCustomField.StateInitialiserCustomFieldId }); } PlanningAppStates.Add(newPlanningAppState); } //set first state to current state if (PlanningAppStates.Count > 0) { PlanningAppStates[0].CurrentState = true; } //Set overall Status to InProgress CurrentPlanningStatus = stateStatus.Where(s => s.Name == StatusList.AppInProgress).SingleOrDefault(); return(this); }
public void updateDueByDates() //Called when inserting a new state to an existing planning app { if (!Completed()) { //Important - put states in order before processing!! PlanningAppStates = PlanningAppStates.OrderBy(s => s.state.OrderId).ToList(); var prevState = new PlanningAppState(); var currState = Current(); var resetCurrent = Current(); while (currState != null) { if (!isFirstState(currState)) { prevState = SeekPrev(); currState.AggregateDueByDate(prevState); } currState = Next(currState); } //Set original state SetCurrent(resetCurrent); } }
public PlanningApp InsertNewPlanningState(StateInitialiserState newStateInitialiser, IEnumerable <StateStatus> stateStatus) { if (!Completed()) { var currentState = Current(); if (newStateInitialiser.OrderId > currentState.state.OrderId) { //Remove states after current state var states = this.PlanningAppStates.ToList(); PlanningAppState newState = new PlanningAppState(); newState.state = newStateInitialiser; newState.CurrentState = false; newState.StateStatus = stateStatus.Where(s => s.Name == StatusList.OnTime).SingleOrDefault(); newState.CompletionDate = null; newState.DueByDate = DateTime.Now; PlanningAppStates.Add(newState); updateDueByDates(); } } return(this); }
private PlanningAppState FirstState(PlanningAppState planningAppState) { return(PlanningAppStates.Count() > 0 ? PlanningAppStates[0] : null); }
private PlanningAppState SeekLastState() { return(PlanningAppStates.Count() > 0 ? PlanningAppStates[PlanningAppStates.Count() - 1] : null); }
public bool isFirstState(PlanningAppState planningAppState) { return(PlanningAppStates.IndexOf(planningAppState) == 0); }
public bool isLastState(PlanningAppState planningAppState) { return(PlanningAppStates.Count() == (PlanningAppStates.IndexOf(planningAppState) + 1)); }
public PlanningAppState Current() { return(PlanningAppStates.Where(s => s.CurrentState == true).SingleOrDefault()); }
public bool Completed() { return(PlanningAppStates.Where(p => p.CurrentState == true).Count() == 0); }