コード例 #1
0
ファイル: DBEntitySave.cs プロジェクト: vipsingh/StackAppCore
        private AnyStatus SaveRelatedData(StackAppContext appContext, EntityModelBase model, IDbConnection connection, IDbTransaction transaction)
        {
            AnyStatus sts = AnyStatus.Success;

            //save child entities
            foreach (var f in model.Attributes)
            {
                var val = f.Value;
                if (val.Field.Type == FieldType.OneToMany && val.IsChanged && val.Value != null && (val.Value as IList).Count > 0)
                {
                    var itemColl = (List <EntityModelBase>)val.Value;
                    var field    = val.Field;
                    var entity   = GetEntity(field.RefObject);
                    foreach (var localModel in itemColl)
                    {
                        SetRelationshipValue(model.ID, field.Name, localModel);
                        sts = entity.Save(appContext, localModel, connection, transaction);
                        if (sts != AnyStatus.Success)
                        {
                            break;
                        }
                    }
                }
            }

            return(sts);
        }
コード例 #2
0
ファイル: DBEntitySave.cs プロジェクト: vipsingh/StackAppCore
        public virtual AnyStatus OnAfterDbSave(StackAppContext appContext, EntityModelBase model, IDbConnection connection, IDbTransaction transaction)
        {
            AnyStatus sts = AnyStatus.Success;

            sts = SaveRelatedData(appContext, model, connection, transaction);

            return(sts);
        }
コード例 #3
0
        public override AnyStatus OnAfterDbSave(StackAppContext appContext, EntityModelBase model, IDbConnection connection, IDbTransaction transaction)
        {
            AnyStatus sts = base.OnAfterDbSave(appContext, model, connection, transaction);

            if (sts == AnyStatus.Success)
            {
                if (model.IsNew)
                {
                }
            }
            return(sts);
        }
コード例 #4
0
        public override AnyStatus OnAfterDbSave(StackAppContext appContext, EntityModelBase model, IDbConnection connection, IDbTransaction transaction)
        {
            AnyStatus sts             = base.OnAfterDbSave(appContext, model, connection, transaction);
            int       defaultItemType = 0;

            if (sts == AnyStatus.Success)
            {
                if (model.IsNew)
                {
                    EntityBuilder.CreateEntityTable(model, connection, transaction, out defaultItemType);
                }
            }
            return(sts);
        }
コード例 #5
0
        public EntityModelBase Generate(UIFormModel model)
        {
            this.ValidatrRequest();

            _formContext.CreateDataModel();

            RecordModel = _formContext.EntityModel;

            SetRelationShip();

            this.SetFieldsModelToRecord(model);
            Status = AnyStatus.Success;

            return(RecordModel);
        }
コード例 #6
0
        public virtual void Build(DataListContext context)
        {
            var defn = GetSourceDefinition(context);

            try {
                OnBuildInit(context, defn);
                Compile(context, defn);
                ExecutePrepareData(context, defn);
            }
            catch (Exception ex)
            {
                Status         = AnyStatus.InvalidData;
                Status.Message = ex.Message;
                return;
            }
        }
コード例 #7
0
        public AnyStatus ExecuteScript(string codeStr)
        {
            currentScriptTag = "Start<>";
            AnyStatus sts = AnyStatus.Success;

            try {
                var parser  = new JavaScriptParser(codeStr);
                var program = parser.ParseScript();

                ExecuteScript(program);
            } catch (Exception ex) {
                sts         = AnyStatus.ScriptFailure;
                sts.Message = currentScriptTag + "::" + ex.Message;
            }

            return(sts);
        }
コード例 #8
0
        public AnyStatus ExecuteFunction <T>(StackAppContext appContext, string codeStr, Dictionary <string, object> param, T output) //Arguments param
        {
            AnyStatus sts = AnyStatus.Success;

            try {
                currentScriptTag = "Start<>";

                var parser  = new JavaScriptParser(codeStr);
                var program = parser.ParseScript();

                _DataProvider        = new ObjectDataProvider(appContext, param);
                _DataProvider.output = output;

                ExecuteBody(program.Body);
            } catch (Exception ex) {
                sts         = AnyStatus.ScriptFailure;
                sts.Message = currentScriptTag + "::" + ex.Message;
            }

            return(sts);
        }
コード例 #9
0
ファイル: DBEntitySave.cs プロジェクト: vipsingh/StackAppCore
        public AnyStatus Save(StackAppContext appContext, EntityModelBase model, IDbConnection connection, IDbTransaction transaction)
        {
            AnyStatus status = AnyStatus.NotInitialized;

            try
            {
                if (model.IsNew)
                {
                    model.SetValue("CREATEDON", DateTime.Now.ToUniversalTime());
                    model.SetValue("CREATEDBY", appContext.UserInfo.UserId);
                    model.SetMasterId(appContext.MasterId);
                }
                model.SetValue("UPDATEDON", DateTime.Now.ToUniversalTime());
                model.SetValue("UPDATEDBY", appContext.UserInfo.UserId);

                if (this.Validate(model))
                {
                    if (model is EntityRecordModel)
                    {
                        ((EntityRecordModel)model).ResolveComputedFields();
                    }
                    status = EntityDBService.SaveEntity(appContext, this, model, connection, transaction);
                    if (status == AnyStatus.Success)
                    {
                        status = OnSaveComplete(appContext, model);
                    }
                }
                else
                {
                    status = AnyStatus.InvalidData;
                }
            }
            catch (AppException ex)
            {
                status         = AnyStatus.SaveFailure;
                status.Message = ex.Message;
            }
            return(status);
        }
コード例 #10
0
 public EntityModelGenerator(EditFormContext context)
 {
     _formContext  = context;
     Status        = AnyStatus.NotInitialized;
     ValueProvider = new FormValueProvider(context);
 }
コード例 #11
0
ファイル: EntityDBSave.cs プロジェクト: vipsingh/StackAppCore
        public static AnyStatus SaveEntity(StackAppContext appContext, IDBEntity entity, EntityModelBase model, IDbConnection connection, IDbTransaction transaction)
        {
            AnyStatus sts = AnyStatus.UpdateFailure;

            var eSave = new EntityDBSave(entity);

            if (model.IsNew)
            {
                var eId = GetNextEntityDBId(entity.EntityId.Code);
                model.SetID(eId);
            }

            IDbConnection  conn;
            IDbTransaction trans;
            bool           isLocalConnection = true;

            if (connection == null)
            {
                conn = DBService.Connection;
                conn.Open();
                trans = conn.BeginTransaction();
            }
            else
            {
                conn              = connection;
                trans             = transaction;
                isLocalConnection = false;
            }

            try
            {
                sts = entity.OnBeforeDbSave(appContext, model, conn, trans);
                if (sts == AnyStatus.Success)
                {
                    eSave.Save(model, conn, trans);
                    sts = entity.OnAfterDbSave(appContext, model, conn, trans);
                    if (sts != AnyStatus.Success)
                    {
                        if (isLocalConnection)
                        {
                            trans.Rollback();
                        }
                    }
                    else
                    {
                        if (isLocalConnection)
                        {
                            trans.Commit();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                sts         = AnyStatus.SaveFailure;
                sts.Message = ex.Message;
                if (isLocalConnection)
                {
                    trans.Rollback();
                }
            }
            finally
            {
                if (isLocalConnection)
                {
                    trans.Dispose();
                    conn.Close();
                }
            }

            return(sts);
        }
コード例 #12
0
        public override AnyStatus Save(StackAppContext appContext, EntityModelBase model)
        {
            AnyStatus status = AnyStatus.NotInitialized;

            return(status);
        }