public static ResultOperation SetVariableByForms(ContentHtml contentHtml, CodeBaseSharedModel codeBaseShared, List <QueryModel> queryModels)
        {
            ResultOperation resultOperation = new ResultOperation();

            foreach (RowHtml row in contentHtml.GetRowHtmls)
            {
                foreach (ColumnHtml column in row.Columns)
                {
                    foreach (var item in column.children)
                    {
                        if (item is FormHtml)
                        {
                            SetVariableByForms(((FormHtml)item).ContentHtml, codeBaseShared, queryModels);
                        }
                        else
                        {
                            if (item is BindingElementBase)
                            {
                                BindingElementBase bindingItem = ((BindingElementBase)item);
                                if (bindingItem.IsInForm(queryModels))
                                {
                                    bindingItem.IsValid(resultOperation);
                                    if (!resultOperation.IsSuccess)
                                    {
                                        return(resultOperation);
                                    }
                                    if (item is TextBoxHtml && ((TextBoxHtml)item).SubType == TextBoxHtml.e_TextBoxType.threadTaskDescription.ToString())
                                    {
                                        codeBaseShared.ThreadTaskDescription = bindingItem.Value.ToStringObjNull();
                                    }
                                    else
                                    {
                                        if (bindingItem.Type != "FILEUPLOAD")
                                        {
                                            string variableName = bindingItem.Map.Split('.').FirstOrDefault();
                                            if (!codeBaseShared.ListSetVariable.Any(c => c.Name == variableName))
                                            {
                                                codeBaseShared.ListSetVariable.Add(new VariableModel(variableName, new DataModel()));
                                            }
                                            codeBaseShared.ListSetVariable.FirstOrDefault(c => c.Name == variableName)[bindingItem.Map] = bindingItem.Value;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(resultOperation);
        }
        public ResultOperation SaveIntoDataBase(ContentHtml contentHtml, sysBpmsThreadTask threadTask, List <VariableModel> setExternalVariable, string threadTaskDescription)
        {
            ResultOperation resultOperation = new ResultOperation();

            try
            {
                base.BeginTransaction();

                //First set variable according to elements.
                //resultOperation = this.SetValuesToElements(contentHtml);

                //Then set external variables, filled by user defined actions.
                if (setExternalVariable != null)
                {
                    foreach (var item in setExternalVariable)
                    {
                        foreach (var dataModel in item.Items)
                        {
                            foreach (var val in dataModel.ToList())
                            {
                                this.SetValueByBinding(val.Key, val.Value);
                            }
                        }
                    }
                }

                if (resultOperation.IsSuccess)
                {
                    resultOperation = this.SaveInto();
                }

                if (resultOperation.IsSuccess)
                {
                    DocumentEngine documentEngine = new DocumentEngine(base.EngineSharedModel, base.UnitOfWork);
                    foreach (FileUploadHtml item in contentHtml.Rows.SelectMany(r => (r is RowHtml ? ((RowHtml)r).Columns : ((AccordionHtml)r).GetListColumn()).SelectMany(d => d.children.Where(f => f is FileUploadHtml).ToList())))
                    {
                        if (resultOperation.IsSuccess)
                        {
                            sysBpmsVariable variable = item.VariableId.ToGuidObjNull() == null ? null :
                                                       new VariableService(base.UnitOfWork).GetInfo(item.VariableId.ToGuidObj());

                            Guid?entityId    = (variable != null && this.SetDataList.ContainsKey(variable.Name)) ? this.SetDataList[variable?.Name].GetValue <Guid>("ID") : (Guid?)null;
                            Guid?entityDefId = variable?.EntityDefID;
                            resultOperation = documentEngine.IsValid(item, variable, entityId, entityDefId, base.EngineSharedModel.CurrentUserName);
                            if (resultOperation.IsSuccess)
                            {
                                resultOperation = documentEngine.SaveFile(item, variable, entityId, entityDefId, "", base.EngineSharedModel.CurrentUserName);
                            }
                        }
                    }
                }
                if (resultOperation.IsSuccess)
                {
                    if (!string.IsNullOrWhiteSpace(this.ThreadTaskDescription))
                    {
                        threadTask.Update(this.ThreadTaskDescription);
                        new ThreadTaskService(base.UnitOfWork).Update(threadTask);
                    }
                }
            }
            catch (Exception ex)
            {
                return(base.ExceptionHandler(ex));
            }
            base.FinalizeService(resultOperation);
            return(resultOperation);
        }