Ejemplo n.º 1
0
        public CodeResultModel SaveButtonCode(ButtonHtml buttonHtml, ResultOperation resultOperation,
                                              FormModel formModel, CodeBaseSharedModel codeBaseShared)
        {
            DesignCodeModel designCodeModel = null;

            if (!string.IsNullOrWhiteSpace(buttonHtml.BackendCoding))
            {
                designCodeModel = DesignCodeUtility.GetDesignCodeFromXml(buttonHtml.BackendCoding);
            }

            if (designCodeModel != null && (designCodeModel.CodeObjects?.Any() ?? false))
            {
                var result = this.ExecuteOnExitFormCode(designCodeModel, formModel, codeBaseShared);
                if (!result.Result)
                {
                    resultOperation.SetHasError();
                    if (!(result?.CodeBaseShared.MessageList?.Any() ?? false))
                    {
                        resultOperation.AddError(LangUtility.Get("Failed.Text", "Engine"));
                    }
                }

                return(result);
            }
            return(null);
        }
Ejemplo n.º 2
0
        private EngineResponseModel SaveContentHtmlByPage(Guid applicationPageId, string buttonControlId)
        {
            ResultOperation     resultOperation  = new ResultOperation();
            RedirectUrlModel    redirectUrlModel = null;
            CodeBaseSharedModel codeBaseShared   = new CodeBaseSharedModel();

            try
            {
                FormModel          formModel   = new FormModel();
                sysBpmsDynamicForm dynamicForm = new DynamicFormService(base.UnitOfWork).GetInfoByPageID(applicationPageId);

                //conver form xml code to json object
                JObject obj = JObject.Parse(dynamicForm.DesignJson);
                //if json object has a control with type = CONTENT
                if (obj != null && obj["type"].ToString() == "CONTENT")
                {
                    formModel       = new FormModel(obj, HtmlElementHelper.MakeModel(base.EngineSharedModel, base.UnitOfWork, HtmlElementHelperModel.e_FormAction.OnPost, dynamicForm), null, null, dynamicForm, false);
                    resultOperation = formModel.ResultOperation;
                }
                this.BeginTransaction();
                if (resultOperation.IsSuccess)
                {
                    CodeResultModel codeResultModel;
                    //It sets variables by form's widgets and adds to the codeBaseShared's ListSetVariable.
                    resultOperation = DataManageEngine.SetVariableByForms(formModel.ContentHtml, codeBaseShared, base.EngineSharedModel.BaseQueryModel);
                    if (resultOperation.IsSuccess)
                    {
                        //execute form button backend code.
                        if (!string.IsNullOrWhiteSpace(buttonControlId))
                        {
                            ButtonHtml        buttonHtml        = (ButtonHtml)formModel.ContentHtml.FindControlByID(buttonControlId);
                            DynamicCodeEngine dynamicCodeEngine = new DynamicCodeEngine(base.EngineSharedModel, base.UnitOfWork);
                            codeResultModel  = dynamicCodeEngine.SaveButtonCode(buttonHtml, resultOperation, formModel, codeBaseShared);
                            redirectUrlModel = codeResultModel?.RedirectUrlModel ?? redirectUrlModel;
                            if (buttonHtml.subtype != ButtonHtml.e_subtype.submit)
                            {
                                //If in code any variable is set, it Will save them all at the end
                                dynamicCodeEngine.SaveExternalVariable(codeResultModel);

                                base.FinalizeService(resultOperation);
                                return(new EngineResponseModel().InitPost(resultOperation, codeBaseShared.MessageList, redirectUrlModel, isSubmit: false, listDownloadModel: codeBaseShared.ListDownloadModel));
                            }
                        }
                        //execute form OnExitFormCode
                        if (!string.IsNullOrWhiteSpace(dynamicForm.OnExitFormCode))
                        {
                            codeResultModel = new DynamicCodeEngine(base.EngineSharedModel, base.UnitOfWork).ExecuteOnExitFormCode(DesignCodeUtility.GetDesignCodeFromXml(dynamicForm.OnExitFormCode), formModel, codeBaseShared);
                            DynamicCodeEngine.SetToErrorMessage(codeResultModel, resultOperation);
                            redirectUrlModel = codeResultModel?.RedirectUrlModel ?? redirectUrlModel;
                        }
                        if (resultOperation.IsSuccess)
                        {
                            //save html element values into database.
                            resultOperation = new DataManageEngine(base.EngineSharedModel, base.UnitOfWork).SaveIntoDataBase(formModel.ContentHtml, null, codeBaseShared.ListSetVariable, null);
                        }
                    }
                }
                base.FinalizeService(resultOperation);

                resultOperation.CurrentObject = formModel;
            }
            catch (Exception ex)
            {
                return(new EngineResponseModel().InitPost(base.ExceptionHandler(ex), codeBaseShared.MessageList, null));
            }

            return(new EngineResponseModel().InitPost(resultOperation, codeBaseShared.MessageList, redirectUrlModel, listDownloadModel: codeBaseShared.ListDownloadModel));
        }