Exemple #1
0
        public static void ConstructRecordObjectFromPostSaveRequest(JSONRecord jr, ref PrimaryKeyRecord rec)
        {
            PrimaryKeyTable t = (PrimaryKeyTable)DatabaseObjects.GetTableObject(jr.TableName);

            t.ResetSelectedColumns();

            rec = new PrimaryKeyRecord(t);
            rec.IsExistsInDatabase = jr.IsExistsInDatabase;

            if ((jr.JRecordValues != null))
            {
                foreach (JRecordValue jRecordValue in jr.JRecordValues)
                {
                    BaseColumn bc = t.TableDefinition.ColumnList.GetByCodeName(jRecordValue.ColumnName);
                    if (!bc.IsValuesReadOnly)
                    {
                        rec.Parse(jRecordValue.ColumnValue, bc);
                    }
                    else if (t.TableDefinition.IsPrimaryKeyElement(bc))
                    {
                        KeyValue kv = new KeyValue();
                        kv.AddElement(jRecordValue.ColumnName, jRecordValue.ColumnValue.ToString());
                        rec.PrimaryKeyValue = kv;
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// This method takes a key and returns a keyvalue.
        /// </summary>
        /// <param name="key">key could be array of primary key values in case of composite primary key or a string containing single primary key value in case of non-composite primary key.</param>
        public static KeyValue GetKeyValue(object key)
        {
            KeyValue kv = null;

            if (!(AreasTable.Instance.TableDefinition.PrimaryKey == null))
            {
                bool isCompositePrimaryKey = false;
                isCompositePrimaryKey = AreasTable.Instance.TableDefinition.PrimaryKey.IsCompositeKey;
                if ((isCompositePrimaryKey && key.GetType().IsArray))
                {
                    //  If the key is composite, then construct a key value.
                    kv = new KeyValue();
                    Array keyArray = ((Array)(key));
                    if (!(keyArray == null))
                    {
                        int        length    = keyArray.Length;
                        ColumnList pkColumns = AreasTable.Instance.TableDefinition.PrimaryKey.Columns;
                        int        index     = 0;
                        foreach (BaseColumn pkColumn in pkColumns)
                        {
                            string keyString = ((keyArray.GetValue(index)).ToString());
                            if (AreasTable.Instance.TableDefinition.TableType == BaseClasses.Data.TableDefinition.TableTypes.Virtual)
                            {
                                kv.AddElement(pkColumn.UniqueName, keyString);
                            }
                            else
                            {
                                kv.AddElement(pkColumn.InternalName, keyString);
                            }

                            index = (index + 1);
                        }
                    }
                }
                else
                {
                    //  If the key is not composite, then get the key value.
                    kv = AreasTable.Instance.TableDefinition.PrimaryKey.ParseValue(((key).ToString()));
                }
            }
            return(kv);
        }
Exemple #3
0
        public static void ConstructRecordObjectFromPostDeleteRequest(JSONRecord jr, ref PrimaryKeyTable pk, ref List <KeyValue> kvList)
        {
            pk = (PrimaryKeyTable)DatabaseObjects.GetTableObject(jr.TableName);

            if ((jr.JRecordValues != null))
            {
                foreach (JRecordValue jRecordValue in jr.JRecordValues)
                {
                    KeyValue kv = new KeyValue();
                    kv.AddElement(jRecordValue.ColumnName, jRecordValue.ColumnValue.ToString());
                    kvList.Add(kv);
                }
            }
        }