Esempio n. 1
0
        public static void Register()
        {
            new Execute(WorkflowOperation.Save)
            {
                CanBeNew      = true,
                CanBeModified = true,
                Execute       = (e, args) =>
                {
                    if (e.MainEntityStrategies.Contains(WorkflowMainEntityStrategy.CreateNew))
                    {
                        var type = e.MainEntityType.ToType();
                        if (CaseActivityLogic.Options.TryGetC(type)?.Constructor == null)
                        {
                            throw new ApplicationException(WorkflowMessage._0NotAllowedFor1NoConstructorHasBeenDefinedInWithWorkflow.NiceToString(WorkflowMainEntityStrategy.CreateNew.NiceToString(), type.NiceName()));
                        }
                    }

                    WorkflowLogic.ApplyDocument(e, args.TryGetArgC <WorkflowModel>(), args.TryGetArgC <WorkflowReplacementModel>(), args.TryGetArgC <List <WorkflowIssue> >() ?? new List <WorkflowIssue>());
                    DynamicCode.OnInvalidated?.Invoke();
                }
            }.Register();

            new ConstructFrom <WorkflowEntity>(WorkflowOperation.Clone)
            {
                Construct = (w, args) =>
                {
                    WorkflowBuilder wb = new WorkflowBuilder(w);

                    var result = wb.Clone();

                    return(result);
                }
            }.Register();

            new Delete(WorkflowOperation.Delete)
            {
                CanDelete = w =>
                {
                    var usedWorkflows = Database.Query <CaseEntity>()
                                        .Where(c => c.Workflow.Is(w) && c.ParentCase != null)
                                        .Select(c => c.ParentCase !.Entity.Workflow.ToLite())
                                        .Distinct()
                                        .ToList();

                    if (usedWorkflows.Any())
                    {
                        return(WorkflowMessage.WorkflowUsedIn0ForDecompositionOrCallWorkflow.NiceToString(usedWorkflows.ToString(", ")));
                    }

                    return(null);
                },

                Delete = (w, _) =>
                {
                    var wb = new WorkflowBuilder(w);
                    wb.Delete();
                    DynamicCode.OnInvalidated?.Invoke();
                }
            }.Register();