public ActionResult Add(string tableName) { 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) { var newkey = key.Replace("values", "").Replace("[", "").Replace("]", "").ToLower(); if (newkey == 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 = "N'" + String.Join("',N'", columnFieldValueList.Select(V => V.ColumnValue)) + "'"; string jsonResult = MasterTableDAL.AddRecord(tableName, strColumns, strValues); return(JsonMax("OK")); }
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")); }