Example #1
0
        public List <DatabaseItemEdit> GetEdit(string tablename, string Id, ApiCall call)
        {
            var db = Kooboo.Data.DB.GetKDatabase(call.Context.WebSite);

            var dbTable = Kooboo.Data.DB.GetTable(db, tablename);

            List <DatabaseItemEdit> result = new List <DatabaseItemEdit>();

            var obj = dbTable.Get(Id);

            foreach (var item in dbTable.Setting.Columns)
            {
                DatabaseItemEdit model = new DatabaseItemEdit()
                {
                    Name = item.Name, IsIncremental = item.IsIncremental, IsUnique = item.IsUnique, IsIndex = item.IsIndex, IsPrimaryKey = item.IsPrimaryKey, Seed = item.Seed, Scale = item.Increment, IsSystem = item.IsSystem
                };

                model.DataType = DatabaseColumnHelper.ToFrontEndDataType(item.ClrType);

                model.ControlType = item.ControlType;
                model.Setting     = item.Setting;

                // get value
                if (obj != null && obj.ContainsKey(model.Name))
                {
                    model.Value = obj[model.Name];
                }

                result.Add(model);
            }
            return(result);
        }
Example #2
0
        public List <DatabaseColumnViewModel> Columns(string table, ApiCall call)
        {
            var db = Kooboo.Data.DB.GetKDatabase(call.Context.WebSite);

            var dbTable = db.GetOrCreateTable(table);

            List <DatabaseColumnViewModel> result = new List <DatabaseColumnViewModel>();

            foreach (var item in dbTable.Setting.Columns)
            {
                if (item.IsSystem && item.Name == IndexedDB.Dynamic.Constants.DefaultIdFieldName)
                {
                    continue;
                }


                DatabaseColumnViewModel model = new DatabaseColumnViewModel()
                {
                    Name = item.Name, IsIncremental = item.IsIncremental, IsUnique = item.IsUnique, IsIndex = item.IsIndex, IsPrimaryKey = item.IsPrimaryKey, Seed = item.Seed, Scale = item.Increment, IsSystem = item.IsSystem
                };

                model.DataType = DatabaseColumnHelper.ToFrontEndDataType(item.ClrType);

                model.ControlType = item.ControlType;
                model.Setting     = item.Setting;

                result.Add(model);
            }
            return(result);
        }