public ContentResult Rows(string TableName, ListTypes ListType, string ListName) { MetadataTable mt = SqlBuilder.DefaultMetadata.FindTable(TableName); SqlBuilder Builder = mt.ToSqlBuilder(ListType != ListTypes.Custom ? ListType.ToString() : ListName); ResultTable result = Builder.Execute(30, false, ResultTable.DateHandlingEnum.ConvertToDate); return(Content(SerializationExtensions.ToJson <dynamic>(result), "application/json")); }
//public ContentResult Save(FormCollection Model, string Table, ListTypes ListType, string ListName) // public ContentResult Save(SaveModel Model) public ContentResult Save(string rowData, string Table, ListTypes ListType, string ListName) { RowData row = SerializationExtensions.FromJson<RowData>(rowData); row.LoadMetadata(); row.LoadMissingColumns<bool>(); SqlBuilder builder = row.Update(false, true); ResultTable result = builder.Execute(); if (result.Count == 1) { builder = row.Select(ListType != ListTypes.Custom ? ListType.ToString() : ListName); //builder = row.Metadata.ToSqlBuilder(ListType != ListTypes.Custom ? ListType.ToString() : ListName); //builder.WhereConditions = row.PrimaryKey(builder); result = builder.Execute(30, false, ResultTable.DateHandlingEnum.ConvertToDate); if (result.Count == 1) { return Content(SerializationExtensions.ToJson<dynamic>(result.First()), "application/json"); } //// object PK = result.First().Column(mt.PrimaryKey.Columns.First().Name); //Builder.BaseTable().WithMetadata().WherePrimaryKey(new object[] { (object)PK }); //ResultTable updated = Builder.Execute(30, false, ResultTable.DateHandlingEnum.ConvertToDate); //if (updated.Count == 1) //{ // return Content(SerializationExtensions.ToJson<dynamic>(updated.First()), "application/json"); //} } //// Retrieve by Primary key //MetadataTable mt = SqlBuilder.DefaultMetadata.FindTable(Table); //List<object> PKs = new List<object>(); //foreach (MetadataColumn mc in mt.PrimaryKey.Columns) //{ // PKs.Add(Model[Table + "_" + mc.Name]); //} //// Create an empty row with the primary key set //RowData row = RowData.Create(mt, true, PKs.ToArray()); //// Change the row //foreach (string key in Model.Keys) //{ // if (!key.StartsWith("__")) // { // string ColumnName = key.Replace(Table, "").Replace("_", ""); // MetadataColumn mc; // if (mt.Columns.TryGetValue(ColumnName, out mc)) // { // if (!mc.IsReadOnly) // { // // row.Column(mc.Name, (object)Model[key]); // row.Column(mc.Name, Model[key]); // } // } // } //} //// Build SQL and update //SqlBuilder builder = row.Update(true, true); //ResultTable result = builder.Execute(30, false); //if (result.Count == 1) //{ // object PK = result.First().Column(mt.PrimaryKey.Columns.First().Name); // SqlBuilder Builder = mt.ToSqlBuilder(ListType != ListTypes.Custom ? ListType.ToString() : ListName); // Builder.BaseTable().WithMetadata().WherePrimaryKey(new object[] { (object)PK }); // ResultTable updated = Builder.Execute(30, false, ResultTable.DateHandlingEnum.ConvertToDate); // if (updated.Count == 1) // { // return Content(SerializationExtensions.ToJson<dynamic>(updated.First()), "application/json"); // } //} return Content(""); }
public ContentResult Rows(string TableName, ListTypes ListType, string ListName) { MetadataTable mt = SqlBuilder.DefaultMetadata.FindTable(TableName); SqlBuilder Builder = mt.ToSqlBuilder(ListType != ListTypes.Custom ? ListType.ToString() : ListName); ResultTable result = Builder.Execute(30, false, ResultTable.DateHandlingEnum.ConvertToDate); return Content(SerializationExtensions.ToJson<dynamic>(result), "application/json"); }
public Object searchListByID(string id, ListTypes lt) { switch (lt) { case (ListTypes.Weapons): foreach (Weapon weapon in this.weapons) { if (weapon.ID.Equals(id)) { return weapon; } } break; case (ListTypes.Armours): foreach (Armour armour in this.armours) { if (armour.ID.Equals(id)) { return armour; } } break; case (ListTypes.Units): foreach (Unit unit in this.attackerunits) { if (unit.ID.Equals(id)) { return unit; } } break; case (ListTypes.Stats): foreach (Stat stat in this.stats) { if (stat.ID.Equals(id)) { return stat; } } break; case (ListTypes.PlayerStats): foreach (PlayerStat stat in this.pstats) { if (stat.ID.Equals(id)) { return stat; } } break; default: this.logger.logBoth(String.Format("Searching for id: {0}, type: {1}", id, lt.ToString())); break; } return null; }
//public ContentResult Save(FormCollection Model, string Table, ListTypes ListType, string ListName) // public ContentResult Save(SaveModel Model) public ContentResult Save(string rowData, string Table, ListTypes ListType, string ListName) { RowData row = SerializationExtensions.FromJson <RowData>(rowData); row.LoadMetadata(); row.LoadMissingColumns <bool>(); SqlBuilder builder = row.Update(false, true); ResultTable result = builder.Execute(); if (result.Count == 1) { builder = row.Select(ListType != ListTypes.Custom ? ListType.ToString() : ListName); //builder = row.Metadata.ToSqlBuilder(ListType != ListTypes.Custom ? ListType.ToString() : ListName); //builder.WhereConditions = row.PrimaryKey(builder); result = builder.Execute(30, false, ResultTable.DateHandlingEnum.ConvertToDate); if (result.Count == 1) { return(Content(SerializationExtensions.ToJson <dynamic>(result.First()), "application/json")); } //// object PK = result.First().Column(mt.PrimaryKey.Columns.First().Name); //Builder.BaseTable().WithMetadata().WherePrimaryKey(new object[] { (object)PK }); //ResultTable updated = Builder.Execute(30, false, ResultTable.DateHandlingEnum.ConvertToDate); //if (updated.Count == 1) //{ // return Content(SerializationExtensions.ToJson<dynamic>(updated.First()), "application/json"); //} } //// Retrieve by Primary key //MetadataTable mt = SqlBuilder.DefaultMetadata.FindTable(Table); //List<object> PKs = new List<object>(); //foreach (MetadataColumn mc in mt.PrimaryKey.Columns) //{ // PKs.Add(Model[Table + "_" + mc.Name]); //} //// Create an empty row with the primary key set //RowData row = RowData.Create(mt, true, PKs.ToArray()); //// Change the row //foreach (string key in Model.Keys) //{ // if (!key.StartsWith("__")) // { // string ColumnName = key.Replace(Table, "").Replace("_", ""); // MetadataColumn mc; // if (mt.Columns.TryGetValue(ColumnName, out mc)) // { // if (!mc.IsReadOnly) // { // // row.Column(mc.Name, (object)Model[key]); // row.Column(mc.Name, Model[key]); // } // } // } //} //// Build SQL and update //SqlBuilder builder = row.Update(true, true); //ResultTable result = builder.Execute(30, false); //if (result.Count == 1) //{ // object PK = result.First().Column(mt.PrimaryKey.Columns.First().Name); // SqlBuilder Builder = mt.ToSqlBuilder(ListType != ListTypes.Custom ? ListType.ToString() : ListName); // Builder.BaseTable().WithMetadata().WherePrimaryKey(new object[] { (object)PK }); // ResultTable updated = Builder.Execute(30, false, ResultTable.DateHandlingEnum.ConvertToDate); // if (updated.Count == 1) // { // return Content(SerializationExtensions.ToJson<dynamic>(updated.First()), "application/json"); // } //} return(Content("")); }
public ListBuilder BuildList(string TableName, ListTypes ListType, string ListTitle = null, string CustomListName = null) { ListBuilder list = null; bool InCache = false; MetadataTable Table = SqlBuilder.DefaultMetadata.FindTable(TableName); if (Table == null) { throw new ArgumentException(string.Format("The table '{0}' was not found in metadata", TableName), "TableName"); } switch (ListType) { case ListTypes.Primary: InCache = PrimaryLists.TryGetValue(Table.Fullname, out list); break; case ListTypes.Secondary: InCache = SecondaryLists.TryGetValue(Table.Fullname, out list); break; case ListTypes.Integrated: InCache = IntegratedLists.TryGetValue(Table.Fullname, out list); break; case ListTypes.Lookup: InCache = LookupLists.TryGetValue(Table.Fullname, out list); break; case ListTypes.Custom: if (string.IsNullOrEmpty(CustomListName)) { throw new ArgumentException("Custom List name must be specified to load a custom list", "CustomListName"); } List<ListBuilder> custom = null; if (CustomLists.TryGetValue(Table.Fullname, out custom)) { InCache = custom.Any(x => x.CustomName.Equals(CustomListName, StringComparison.OrdinalIgnoreCase)); if (InCache) { list = custom.First(x => x.CustomName.Equals(CustomListName, StringComparison.OrdinalIgnoreCase)); } } break; default: break; } if (list != null) { return list; } list = new ListBuilder() { ListType = ListType, TableName = Table.Fullname, Title = string.IsNullOrEmpty(ListTitle) ? Table.DisplayName : ListTitle, CustomName = CustomListName, }; list.AllowNew = list.AllowEdit = list.AllowDelete = ListType != ListTypes.Lookup; string ListName = ListType != ListTypes.Custom ? ListType.ToString() : CustomListName; List<MetadataColumn> columns = new List<MetadataColumn>(Table.PrimaryKey.Columns); List<string> columnDef = null; if (!Table.ListDefinitions.TryGetValue(ListName, out columnDef)) { // No standard specified columnDef = new List<string>(Table.Columns.Values.Where(x => x.IsPrimaryKey == false && x.IsRowGuid == false).Select(x => x.Name)); } foreach (MetadataColumn column in columns) { list.Columns.Add(new ListColumn() { ColumnName = column.Name, DisplayName = column.DisplayName, IsVisible = true, ColumnDataType = ListColumn.GetColumnDataType(column.SqlDataType) }); } list.Builder = Table.ToSqlBuilder(list.ListType != ListTypes.Custom ? list.ListType.ToString() : CustomListName); foreach (string cdef in columnDef) { MetadataColumn mc; SqlDbType type = SqlDbType.NVarChar; string Display = cdef; string ColName = cdef; if (cdef.IndexOf('=') > 0) { ColName = cdef.Split('=')[0]; Display = cdef.Split('=')[1]; } if (!Table.Columns.TryGetValue(ColName, out mc)) { Field f = list.Builder.Tables.SelectMany(x => x.FieldList).FirstOrDefault(x => x.Alias != null && x.Alias.Equals(ColName)); if (f != null) { type = f.SqlDataType; //MetadataTable mtRelated = SqlBuilder.DefaultMetadata.FindTable((f.Table.Schema != null ? f.Table.Schema + "." : "") + f.Table.Name); //MetadataColumn mcRelated; //if (mtRelated.Columns.TryGetValue(f.Name, out mcRelated)) //{ // Display = mcRelated.DisplayName; //} } } else { Display = mc.DisplayName; ColName = mc.Name; type = mc.SqlDataType; } list.Columns.Add(new ListColumn() { ColumnName = ColName, DisplayName = Display, IsVisible = mc != null ? !mc.IsForeignKey : true, ColumnDataType = ListColumn.GetColumnDataType(type) }); } //columns.AddRange( // Table.Columns.Values.Where(x => columnDef.Contains(x.Name)) // ); ToCache(list, ListType, CustomListName); return list; }
public ListBuilder BuildList(string TableName, ListTypes ListType, string ListTitle = null, string CustomListName = null) { ListBuilder list = null; bool InCache = false; MetadataTable Table = SqlBuilder.DefaultMetadata.FindTable(TableName); if (Table == null) { throw new ArgumentException(string.Format("The table '{0}' was not found in metadata", TableName), "TableName"); } switch (ListType) { case ListTypes.Primary: InCache = PrimaryLists.TryGetValue(Table.Fullname, out list); break; case ListTypes.Secondary: InCache = SecondaryLists.TryGetValue(Table.Fullname, out list); break; case ListTypes.Integrated: InCache = IntegratedLists.TryGetValue(Table.Fullname, out list); break; case ListTypes.Lookup: InCache = LookupLists.TryGetValue(Table.Fullname, out list); break; case ListTypes.Custom: if (string.IsNullOrEmpty(CustomListName)) { throw new ArgumentException("Custom List name must be specified to load a custom list", "CustomListName"); } List <ListBuilder> custom = null; if (CustomLists.TryGetValue(Table.Fullname, out custom)) { InCache = custom.Any(x => x.CustomName.Equals(CustomListName, StringComparison.OrdinalIgnoreCase)); if (InCache) { list = custom.First(x => x.CustomName.Equals(CustomListName, StringComparison.OrdinalIgnoreCase)); } } break; default: break; } if (list != null) { return(list); } list = new ListBuilder() { ListType = ListType, TableName = Table.Fullname, Title = string.IsNullOrEmpty(ListTitle) ? Table.DisplayName : ListTitle, CustomName = CustomListName, }; list.AllowNew = list.AllowEdit = list.AllowDelete = ListType != ListTypes.Lookup; string ListName = ListType != ListTypes.Custom ? ListType.ToString() : CustomListName; List <MetadataColumn> columns = new List <MetadataColumn>(Table.PrimaryKey.Columns); List <string> columnDef = null; if (!Table.ListDefinitions.TryGetValue(ListName, out columnDef)) { // No standard specified columnDef = new List <string>(Table.Columns.Values.Where(x => x.IsPrimaryKey == false && x.IsRowGuid == false).Select(x => x.Name)); } foreach (MetadataColumn column in columns) { list.Columns.Add(new ListColumn() { ColumnName = column.Name, DisplayName = column.DisplayName, IsVisible = true, ColumnDataType = ListColumn.GetColumnDataType(column.SqlDataType) }); } list.Builder = Table.ToSqlBuilder(list.ListType != ListTypes.Custom ? list.ListType.ToString() : CustomListName); foreach (string cdef in columnDef) { MetadataColumn mc; SqlDbType type = SqlDbType.NVarChar; string Display = cdef; string ColName = cdef; if (cdef.IndexOf('=') > 0) { ColName = cdef.Split('=')[0]; Display = cdef.Split('=')[1]; } if (!Table.Columns.TryGetValue(ColName, out mc)) { Field f = list.Builder.Tables.SelectMany(x => x.FieldList).FirstOrDefault(x => x.Alias != null && x.Alias.Equals(ColName)); if (f != null) { type = f.SqlDataType; //MetadataTable mtRelated = SqlBuilder.DefaultMetadata.FindTable((f.Table.Schema != null ? f.Table.Schema + "." : "") + f.Table.Name); //MetadataColumn mcRelated; //if (mtRelated.Columns.TryGetValue(f.Name, out mcRelated)) //{ // Display = mcRelated.DisplayName; //} } } else { Display = mc.DisplayName; ColName = mc.Name; type = mc.SqlDataType; } list.Columns.Add(new ListColumn() { ColumnName = ColName, DisplayName = Display, IsVisible = mc != null ? !mc.IsForeignKey : true, ColumnDataType = ListColumn.GetColumnDataType(type) }); } //columns.AddRange( // Table.Columns.Values.Where(x => columnDef.Contains(x.Name)) // ); ToCache(list, ListType, CustomListName); return(list); }
public Object searchListByID(string id, ListTypes lt) { switch (lt) { case (ListTypes.Weapons): foreach (Weapon weapon in this.weapons) { if (weapon.ID.Equals(id)) { return(weapon); } } break; case (ListTypes.Armours): foreach (Armour armour in this.armours) { if (armour.ID.Equals(id)) { return(armour); } } break; case (ListTypes.Units): foreach (Unit unit in this.attackerunits) { if (unit.ID.Equals(id)) { return(unit); } } break; case (ListTypes.Stats): foreach (Stat stat in this.stats) { if (stat.ID.Equals(id)) { return(stat); } } break; case (ListTypes.PlayerStats): foreach (PlayerStat stat in this.pstats) { if (stat.ID.Equals(id)) { return(stat); } } break; default: this.logger.logBoth(String.Format("Searching for id: {0}, type: {1}", id, lt.ToString())); break; } return(null); }