public ActionResult WorkflowConfiguration(Guid workflowId, bool displayOnly = true) { var entityBO = BusinessLogic.Core.GetFactory().GetInstance <IEntityBO>(); var wfBO = BusinessLogic.Core.GetFactory().GetInstance <IWorkflowBO>(); var conditionBO = BusinessLogic.Core.GetFactory().GetInstance <IConditionBO>(); WorkflowStateModel model = new WorkflowStateModel(); model.EditMode = !displayOnly; model.ConditionList = conditionBO.GetAll().Select(o => new ConditionModel() { Id = o.Id, Name = o.Name, EntityId = o.EntityId, ConditionType = o.ConditionType, ConditionDisplayText = conditionBO.GetDisplayText(o) }).ToList(); model.EntityList = entityBO.GetAll().Select(o => new SelectListItem() { Value = o.Id.ToString(), Selected = false, Text = o.Description }); List <WorkflowStateDataContract> workflowStateList = new List <WorkflowStateDataContract>(); Session["WorkflowStateList"] = workflowStateList; List <WorkflowStateTransitionDataContract> workflowStateTransitionList = new List <WorkflowStateTransitionDataContract>(); Session["WorkflowStateTransitionList"] = workflowStateTransitionList; if (workflowId == Guid.Empty) { ViewBag.Message = "Novo Workflow"; model.WorkflowId = Guid.NewGuid(); model.EditMode = true; return(View(model)); } ViewBag.Message = "Editar Workflow"; WorkflowDataContract dt = wfBO.GetById(workflowId); model.Name = dt.Description; model.EntityId = dt.EntityId; model.Active = dt.Active; model.ConditionId = dt.StartConditionId; model.TriggerDecisionText = model.ConditionList.Where(o => o.Id.Equals(dt.StartConditionId)).First().ConditionDisplayText; model.WorkflowId = dt.Id; model.WorkflowStateList = dt.WorkflowStateList; Session["WorkflowStateList"] = dt.WorkflowStateList; Session["WorkflowStateTransitionList"] = dt.WorkflowStateTransitionList; return(View(model)); }
public ActionResult SaveWorkflow(WorkflowStateModel model) { var workflowBO = BusinessLogic.Core.GetFactory().GetInstance <BusinessLogic.BusinessObject.IWorkflowBO>(); WorkflowDataContract dt = new WorkflowDataContract(); List <WorkflowStateDataContract> workflowStateList = (List <WorkflowStateDataContract>)Session["WorkflowStateList"]; List <WorkflowStateTransitionDataContract> workflowStateTransitionList = (List <WorkflowStateTransitionDataContract>)Session["WorkflowStateTransitionList"]; bool update = !model.WorkflowId.Equals(Guid.Empty); dt.Active = model.Active; dt.EntityId = model.EntityId; dt.Description = model.Name; dt.StartConditionId = model.ConditionId; dt.WorkflowStateList = workflowStateList; dt.WorkflowStateTransitionList = workflowStateTransitionList; if (!update) { dt.Id = Guid.NewGuid(); var result = workflowBO.Add(dt); } else { dt.Id = model.WorkflowId; workflowBO.Update(dt); } if (model.Active) { return(RedirectToAction("WorkflowList", "Workflow")); } else { return(RedirectToAction("WorkflowTransitionDetail", "Workflow", new { workflowId = dt.Id, displayOnly = false })); } }
public Common.OperationResult Update(WorkflowDataContract dataContract) { var handler = DataAccess.Core.GetFactory().GetInstance <IWorkflowHandler>(); var handlerTransition = DataAccess.Core.GetFactory().GetInstance <IWorkflowStateTransitionHandler>(); var handlerState = DataAccess.Core.GetFactory().GetInstance <IWorkflowStateHandler>(); var result = handler.Update(dataContract); if (result.Status != Common.OperationResultStatus.Succesfull) { return(result); } var stateList = handlerState.GetAll(dataContract.Id); foreach (var item in dataContract.WorkflowStateList) { if (!stateList.Any(o => o.Id.Equals(item.Id))) { item.WorkflowId = dataContract.Id; result = this.AddState(item); if (result.Status != Common.OperationResultStatus.Succesfull) { return(result); } } else { result = handlerState.Update(item); if (result.Status != Common.OperationResultStatus.Succesfull) { return(result); } } } var tranList = handlerTransition.GetAll(dataContract.Id); foreach (var item in dataContract.WorkflowStateTransitionList) { if (!tranList.Any(o => o.Id.Equals(item.Id))) { item.WorkflowId = dataContract.Id; result = this.AddStateTransition(item); if (result.Status != Common.OperationResultStatus.Succesfull) { return(result); } } } tranList = handlerTransition.GetAll(dataContract.Id); foreach (var item in tranList) { if (!dataContract.WorkflowStateTransitionList.Any(o => o.Id.Equals(item.Id))) { result = handlerTransition.Delete(item); if (result.Status != Common.OperationResultStatus.Succesfull) { return(result); } } } stateList = handlerState.GetAll(dataContract.Id); foreach (var item in stateList) { if (!dataContract.WorkflowStateList.Any(o => o.Id.Equals(item.Id))) { result = handlerState.Delete(item); if (result.Status != Common.OperationResultStatus.Succesfull) { return(result); } } } return(result); }