public WorkflowStep GetCurrentWorkflowStep(CodeTorch.Core.Workflow workflow, string entityIDValue) { WorkflowStep retVal = null; List <ScreenDataCommandParameter> parameters = new List <ScreenDataCommandParameter>(); ScreenDataCommandParameter p = null; p = new ScreenDataCommandParameter(ParameterWorkflowCode, workflow.Code); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterEntityType, workflow.EntityName); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterEntityID, entityIDValue); parameters.Add(p); //get data from data command DataTable data = GetDataForDataCommand(DataCommandWorkflowGetCurrentStep, parameters); if (data.Rows.Count > 0) { string CurrentCode = data.Rows[0][ColumnCurrentStepCode].ToString(); retVal = workflow.GetStepByCode(CurrentCode); } return(retVal); }
public bool ChangeWorkflowStep(CodeTorch.Core.Workflow workflow, WorkflowNextStep nextStep, string entityIDValue, string comment) { bool success = false; //get current workflow step WorkflowStep currentStep = GetCurrentWorkflowStep(workflow, entityIDValue); //see if next workflowstep is in possible WorkflowNextStep validNextStep = currentStep.PossibleNextSteps. Where(s => s.Code.ToLower() == nextStep.Code.ToLower()).SingleOrDefault(); if (validNextStep != null) { //check comments if ((validNextStep.RequireComment) && (String.IsNullOrEmpty(comment))) { throw new ApplicationException("Comments are required to change to this step"); } else { WorkflowStep step = workflow.GetStepByCode(validNextStep.Code); string userName; userName = UserIdentityService.GetInstance().IdentityProvider.GetUserName(); using (TransactionScope rootScope = TransactionUtils.CreateTransactionScope()) { foreach (BaseWorkflowAction action in step.Actions) { action.Execute(null, workflow.Code, currentStep.Code, validNextStep.Code, entityIDValue, comment, userName); } //update workflow step SetStep(workflow, step, entityIDValue, comment); if (step.UpdateEntityWithStatusCode) { //update existing table status SetEntityStatus(workflow, step, entityIDValue); } success = true; rootScope.Complete(); } } } else { //invalid - someone may have changed status throw new ApplicationException("Status cannot be changed at this time"); } return(success); }