Пример #1
0
        public ActionResult Update(string tableName)
        {
            Dictionary <string, string> ColumnList           = MasterTableDAL.GetColumns(tableName);
            List <ColumnFieldValue>     columnFieldValueList = new List <ColumnFieldValue>();
            var primaryKeyName = MasterTableDAL.GetPrimaryKey(tableName);

            foreach (var item in ColumnList)
            {
                foreach (string key in Request.Form.AllKeys)
                {
                    var newkey = key.Replace("values", "").Replace("[", "").Replace("]", "").ToLower();
                    if (newkey == item.Key.ToLower() && newkey != primaryKeyName.ToLower())
                    {
                        var columnFieldValue = new ColumnFieldValue();
                        columnFieldValue.ColumnName  = item.Key;
                        columnFieldValue.ColumnValue = Request.Form[key];
                        columnFieldValue.ColumnType  = item.Value;
                        columnFieldValueList.Add(columnFieldValue);
                    }
                }
            }

            //create column string
            string strColumnUpdate = "";

            foreach (var column in columnFieldValueList)
            {
                switch (column.ColumnType)
                {
                case "System.Int64":
                case "System.Int32":
                case "System.Boolean":
                    strColumnUpdate = strColumnUpdate + column.ColumnName + "=" + column.ColumnValue + ",";
                    break;

                case "System.String":
                case "System.DateTime":
                    strColumnUpdate = strColumnUpdate + column.ColumnName + "='" + column.ColumnValue + "',";
                    break;
                }
            }
            strColumnUpdate = strColumnUpdate.TrimEnd(',');

            //audit fields
            strColumnUpdate = strColumnUpdate + " WHERE " + primaryKeyName + " = " + Request.Form["key"];
            MasterTableDAL.UpdateRecord(tableName, strColumnUpdate);
            return(Content("{\"Result\":\"OK\"}", "application/json"));
        }
Пример #2
0
        public ActionResult Add()
        {
            string tableName = "";

            if (!String.IsNullOrEmpty(Request.QueryString["tableName"]))
            {
                tableName = Request.QueryString["tableName"];
            }
            //we will be receiving all values in form variables.
            Dictionary <string, string> ColumnList           = MasterTableDAL.GetColumns(tableName);
            List <ColumnFieldValue>     columnFieldValueList = new List <ColumnFieldValue>();

            foreach (var item in ColumnList)
            {
                if (item.Key == ColumnList.FirstOrDefault().Key)
                {
                    continue;
                }
                foreach (string key in Request.Form.AllKeys)
                {
                    if (key.Replace("values", "").Replace("[", "").Replace("]", "").ToLower() == item.Key.ToLower())
                    {
                        var columnFieldValue = new ColumnFieldValue();
                        columnFieldValue.ColumnName  = item.Key;
                        columnFieldValue.ColumnValue = Request.Form[key];
                        columnFieldValue.ColumnType  = item.Value;
                        columnFieldValueList.Add(columnFieldValue);
                    }
                }
            }

            //create column string
            string strColumns = String.Join(",", columnFieldValueList.Select(x => x.ColumnName));
            string strValues  = "'" + String.Join("',N'", columnFieldValueList.Select(V => V.ColumnValue)) + "'";

            string jsonResult = MasterTableDAL.AddRecord(tableName, strColumns, strValues);

            return(JsonMax("OK"));
        }