public ActionResult TableJson([ModelBinder(typeof(DataTables.AspNet.Mvc5.ModelBinder))] DataTables.AspNet.Core.IDataTablesRequest request) { JqueryDataTable.Field[] fields = new JqueryDataTable.Field[] { new JqueryDataTable.Field("Id"), new JqueryDataTable.Field("Name", true), }; JsonResult jr = JqueryDataTable.Index(request, db.Database.Connection, "FROM Companies", fields); List <object[]> cs = (List <object[]>)(((dynamic)jr.Data).Data); Bot.DbConnection dbc = Cliver.Bot.DbConnection.CreateFromNativeConnection(db.Database.Connection); for (int i = 0; i < cs.Count; i++) { object[] fs = cs[i]; DateTime t = Cliver.Bot.DbSettings.Get <DateTime>(dbc, Cliver.ProductIdentifier.SettingsKey.SCOPE, Cliver.ProductIdentifier.SettingsKey.COMPANY + (int)fs[0] + Cliver.ProductIdentifier.SettingsKey.ANALYSIS_TIME); Array.Resize(ref fs, fs.Length + 1); if (t != default(DateTime)) { fs[fs.Length - 1] = t.ToString("yyyy-MM-dd HH:mm:ss"); } else { fs[fs.Length - 1] = "no analysis was done yet"; } cs[i] = fs; } //cs.Insert(0, new object[] { ProductIdentifier.Configuration.NO_COMPANY_DEPENDENT, "-- DEFAULT --", "" }); return(jr); }
public ActionResult TableJson2([ModelBinder(typeof(DataTables.AspNet.Mvc5.ModelBinder))] DataTables.AspNet.Core.IDataTablesRequest request) { Bot.DbConnection dbc = Cliver.Bot.DbConnection.CreateFromNativeConnection(db.Database.Connection); //dbc.Get("DROP TABLE [#ProductIdentifierConfig2]").Execute(); string fs = ""; if (db.Companies.Count() > 0) { fs = ", [" + string.Join("] CHAR(2) NOT NULL DEFAULT '', [", db.Companies.Select(c => c.Name)) + "] CHAR(2) NOT NULL DEFAULT '' "; } string sql = @"IF OBJECT_ID('tempdb..[#ProductIdentifierConfig2]') IS NOT NULL DROP TABLE [#ProductIdentifierConfig2] ELSE CREATE TABLE [#ProductIdentifierConfig2] ([C1IdC2Id] NVARCHAR (100) NOT NULL" + fs + ")"; dbc.Get(sql).Execute(); List <string> keys = Cliver.Bot.DbSettings.GetKeys(dbc, Cliver.ProductIdentifier.SettingsKey.SCOPE, Cliver.ProductIdentifier.SettingsKey.CATEGORY_MAP + "%"); foreach (string k in keys) { Match m = Regex.Match(k, @"(\d+),(\d+)$", RegexOptions.Singleline); int c1_i = int.Parse(m.Groups[1].Value); int c2_i = int.Parse(m.Groups[2].Value); string c1_n = db.Companies.Where(c => c.Id == c1_i).Select(c => c.Name).FirstOrDefault(); if (c1_n == null) { continue; } string c2_n = db.Companies.Where(c => c.Id == c2_i).Select(c => c.Name).FirstOrDefault(); if (c2_n == null) { continue; } dbc.Get(@"INSERT INTO [#ProductIdentifierConfig2] (C1IdC2Id,[" + c1_n + "],[" + c2_n + "]) VALUES('" + m.Groups[0].Value + "','+','+')").Execute(); } List <JqueryDataTable.Field> fields = new List <JqueryDataTable.Field> { new JqueryDataTable.Field("C1IdC2Id", false) }; fields.AddRange(from c in db.Companies.ToList() select new JqueryDataTable.Field("[" + c.Name + "]", true, 0, null)); return(JqueryDataTable.Index(request, db.Database.Connection, "FROM #ProductIdentifierConfig2", fields.ToArray())); }