public async Task ExecuteAsync(RecipeExecutionContext context) { if (!String.Equals(context.Name, "WorkflowType", StringComparison.OrdinalIgnoreCase)) { return; } var model = context.Step.ToObject <WorkflowStepModel>(); foreach (JObject token in model.Data) { var workflow = token.ToObject <WorkflowType>(); var existing = await _workflowTypeStore.GetAsync(workflow.WorkflowTypeId); if (existing == null) { workflow.Id = 0; } else { await _workflowTypeStore.DeleteAsync(existing); } await _workflowTypeStore.SaveAsync(workflow); } }
public async Task <IActionResult> EditProperties(WorkflowTypePropertiesViewModel viewModel, int?id) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageWorkflows)) { return(Forbid()); } if (!ModelState.IsValid) { return(View(viewModel)); } var isNew = id == null; var workflowType = default(WorkflowType); if (isNew) { workflowType = new WorkflowType(); workflowType.WorkflowTypeId = _workflowTypeIdGenerator.GenerateUniqueId(workflowType); } else { workflowType = await _session.GetAsync <WorkflowType>(id.Value); if (workflowType == null) { return(NotFound()); } } workflowType.Name = viewModel.Name?.Trim(); workflowType.IsEnabled = viewModel.IsEnabled; workflowType.IsSingleton = viewModel.IsSingleton; workflowType.LockTimeout = viewModel.LockTimeout; workflowType.LockExpiration = viewModel.LockExpiration; workflowType.DeleteFinishedWorkflows = viewModel.DeleteFinishedWorkflows; await _workflowTypeStore.SaveAsync(workflowType); return(isNew ? RedirectToAction(nameof(Edit), new { workflowType.Id }) : Url.IsLocalUrl(viewModel.ReturnUrl) ? (IActionResult)this.Redirect(viewModel.ReturnUrl, true) : RedirectToAction(nameof(Index))); }
public async Task <IActionResult> InsertSnippet(string workflowsnippetname, int workflowTypeId, string returnUrl) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageWorkflows)) { return(Forbid()); } var workflowSnippet = await GetWorkFlowSnippet(workflowsnippetname); var sourceworkflowSnippetToInsert = workflowSnippet.WorkFlowType; var targetWorkflowType = await _workflowTypeStore.GetAsync(workflowTypeId); //copy source workflow into target workflow and save foreach (var act in sourceworkflowSnippetToInsert.Activities) { targetWorkflowType.Activities.Add(new ActivityRecord() { ActivityId = act.ActivityId, Name = act.Name, Properties = act.Properties, X = act.X, Y = act.Y, IsStart = act.IsStart }); } foreach (var trans in sourceworkflowSnippetToInsert.Transitions) { targetWorkflowType.Transitions.Add(new Transition { Id = trans.Id, SourceActivityId = trans.SourceActivityId, DestinationActivityId = trans.DestinationActivityId, SourceOutcomeName = trans.SourceOutcomeName }); } await _workflowTypeStore.SaveAsync(targetWorkflowType); // No editor to show; short-circuit to the "POST" action. return(Url.IsLocalUrl(returnUrl) ? (IActionResult)Redirect(returnUrl) : RedirectToAction("Edit", "WorkflowType", new { id = workflowTypeId })); /*//var activity = _activityLibrary.InstantiateActivity(activityName); * var activityId = _activityIdGenerator.GenerateUniqueId(new ActivityRecord()); * var activityEditor = await _activityDisplayManager.BuildEditorAsync(activity, _updateModelAccessor.ModelUpdater, isNew: true); * * activityEditor.Metadata.Type = "Activity_Edit"; * * var viewModel = new ActivityEditViewModel * { * Activity = activity, * ActivityId = activityId, * ActivityEditor = activityEditor, * WorkflowTypeId = workflowTypeId, * ReturnUrl = returnUrl * }; * * if (!activity.HasEditor) * { * // No editor to show; short-circuit to the "POST" action. * return await Create(activityName, viewModel); * } * * return View(viewModel);*/ }