|
@@ -102,7 +102,7 @@ namespace InABox.Core
|
|
|
/// <see langword="true"/> if this table should be loaded - in some cases a table's data should loaded manually.<br/>
|
|
|
/// Set to <see langword="false"/> if this is the case.
|
|
|
/// </param>
|
|
|
- void AddTable<TType>(Filter<TType>? filter, Columns<TType>? columns, bool isdefault = false, string? alias = null, bool shouldLoad = true);
|
|
|
+ void AddTable<TType>(Filter<TType>? filter, Columns<TType>? columns, SortOrder<TType>? sort, bool isdefault = false, string? alias = null, bool shouldLoad = true);
|
|
|
void LinkTable(Type parenttype, string parentcolumn, Type childtype, string childcolumn, string? parentalias = null, string? childalias = null, bool isLookup = false);
|
|
|
void LinkTable(Type parenttype, string parentcolumn, string childalias, string childcolumn, string? parentalias = null, bool isLookup = false);
|
|
|
|
|
@@ -110,11 +110,11 @@ namespace InABox.Core
|
|
|
string? childalias = null, bool isLookup = false);
|
|
|
|
|
|
void AddChildTable<TParent, TChild>(Expression<Func<TParent, object>> parentcolumn, Expression<Func<TChild, object>> childcolumn,
|
|
|
- Filter<TChild>? filter = null, Columns<TChild>? columns = null, bool isdefault = false, string? parentalias = null,
|
|
|
+ Filter<TChild>? filter = null, Columns<TChild>? columns = null, SortOrder<TChild>? sort = null, bool isdefault = false, string? parentalias = null,
|
|
|
string? childalias = null);
|
|
|
|
|
|
void AddLookupTable<TSource, TLookup>(Expression<Func<TSource, object>> sourcecolumn, Expression<Func<TLookup, object>> lookupcolumn,
|
|
|
- Filter<TLookup>? filter = null, Columns<TLookup>? columns = null, bool isdefault = false, string? sourcealias = null,
|
|
|
+ Filter<TLookup>? filter = null, Columns<TLookup>? columns = null, SortOrder<TLookup>? sort = null, bool isdefault = false, string? sourcealias = null,
|
|
|
string? lookupalias = null);
|
|
|
|
|
|
/// <summary>
|
|
@@ -139,7 +139,15 @@ namespace InABox.Core
|
|
|
/// <param name="alias">The name of the table, defaulting to <typeparamref name="TType"/></param>
|
|
|
/// <returns>The columns.</returns>
|
|
|
Columns<TType>? GetColumns<TType>(string? alias = null);
|
|
|
-
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Gets the sort order for a given table, which is used during <see cref="LoadModel(IEnumerable{string}, IDataModelQueryDef[]).
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TType">The type of the table to get the columns of.</typeparam>
|
|
|
+ /// <param name="alias">The name of the table, defaulting to <typeparamref name="TType"/></param>
|
|
|
+ /// <returns>The sort order.</returns>
|
|
|
+ SortOrder<TType>? GetSortOrder<TType>(string? alias = null);
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Sets the filter for a given table, which is used during <see cref="LoadModel(IEnumerable{string}, IDataModelQueryDef[]).
|
|
|
/// </summary>
|
|
@@ -147,6 +155,7 @@ namespace InABox.Core
|
|
|
/// <param name="filter">The new filter.</param>
|
|
|
/// <param name="alias">The name of the table, defaulting to <typeparamref name="TType"/></param>
|
|
|
void SetFilter<TType>(Filter<TType>? filter, string? alias = null);
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Sets the columns for a given table, which are used during <see cref="LoadModel(IEnumerable{string}, IDataModelQueryDef[]).
|
|
|
/// </summary>
|
|
@@ -154,6 +163,16 @@ namespace InABox.Core
|
|
|
/// <param name="columns">The new columns.</param>
|
|
|
/// <param name="alias">The name of the table, defaulting to <typeparamref name="TType"/>.</param>
|
|
|
void SetColumns<TType>(Columns<TType>? columns, string? alias = null);
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Sets the sort order for a given table, which are used during <see cref="LoadModel(IEnumerable{string}, IDataModelQueryDef[]).
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="TType">The type of the table.</typeparam>
|
|
|
+ /// <param name="sort">The new sort order.</param>
|
|
|
+ /// <param name="alias">The name of the table, defaulting to <typeparamref name="TType"/>.</param>
|
|
|
+ void SetSortOrder<TType>(SortOrder<TType>? sort, string? alias = null);
|
|
|
+
|
|
|
+
|
|
|
void SetIsDefault<TType>(bool isDefault, string? alias = null);
|
|
|
void SetShouldLoad<TType>(bool shouldLoad, string? alias = null);
|
|
|
|
|
@@ -186,10 +205,10 @@ namespace InABox.Core
|
|
|
|
|
|
public DataModel()
|
|
|
{
|
|
|
- AddTable<CompanyInformation>(null, null, true);
|
|
|
- AddChildTable<CompanyInformation, Document>(x => x.Logo.ID, x => x.ID, null, null, true, null, "CompanyLogo");
|
|
|
+ AddTable<CompanyInformation>(null, null, null, true);
|
|
|
+ AddChildTable<CompanyInformation, Document>(x => x.Logo.ID, x => x.ID, null, null, null, true, null, "CompanyLogo");
|
|
|
|
|
|
- AddTable(new Filter<User>(x => x.ID).IsEqualTo(ClientFactory.UserGuid), null, true);
|
|
|
+ AddTable(new Filter<User>(x => x.ID).IsEqualTo(ClientFactory.UserGuid), null, null, true);
|
|
|
}
|
|
|
|
|
|
public IEnumerable<KeyValuePair<string, DataModelTable>> ModelTables => _tables;
|
|
@@ -341,14 +360,15 @@ namespace InABox.Core
|
|
|
{
|
|
|
private bool shouldLoad;
|
|
|
|
|
|
- public DataModelTable(Type? type, CoreTable table, bool isDefault, IFilter? filter, IColumns? columns, bool shouldLoad = true)
|
|
|
+ public DataModelTable(Type? type, CoreTable table, bool isDefault, IFilter? filter, IColumns? columns, ISortOrder? sort, bool? shouldLoad = true)
|
|
|
{
|
|
|
Type = type;
|
|
|
Table = table;
|
|
|
IsDefault = isDefault;
|
|
|
Filter = filter;
|
|
|
Columns = columns;
|
|
|
- ShouldLoad = shouldLoad;
|
|
|
+ Sort = sort;
|
|
|
+ ShouldLoad = shouldLoad ?? true;
|
|
|
}
|
|
|
|
|
|
public Type? Type { get; }
|
|
@@ -360,6 +380,8 @@ namespace InABox.Core
|
|
|
public IFilter? Filter { get; set; }
|
|
|
|
|
|
public IColumns? Columns { get; set; }
|
|
|
+
|
|
|
+ public ISortOrder? Sort { get; set; }
|
|
|
|
|
|
public bool ShouldLoad
|
|
|
{
|
|
@@ -515,7 +537,7 @@ namespace InABox.Core
|
|
|
{
|
|
|
var name = TableName(type, alias);
|
|
|
if (!_tables.ContainsKey(name))
|
|
|
- _tables[name] = new DataModelTable(type, table, isdefault, null, null, false);
|
|
|
+ _tables[name] = new DataModelTable(type, table, isdefault, null, null, null, false);
|
|
|
else
|
|
|
throw new Exception(string.Format("[{0}] already exists in this data model!", name));
|
|
|
}
|
|
@@ -568,7 +590,7 @@ namespace InABox.Core
|
|
|
|
|
|
public void AddTable(string alias, CoreTable table, bool isdefault = false) => AddTable(null, table, isdefault, alias);
|
|
|
|
|
|
- public void AddTable<TType>(Filter<TType>? filter, Columns<TType>? columns, bool isdefault = false, string? alias = null, bool shouldLoad = true)
|
|
|
+ public void AddTable<TType>(Filter<TType>? filter, Columns<TType>? columns, SortOrder<TType>? sort, bool isdefault = false, string? alias = null, bool shouldLoad = true)
|
|
|
{
|
|
|
var name = TableName<TType>(alias);
|
|
|
if (!_tables.ContainsKey(name))
|
|
@@ -582,24 +604,24 @@ namespace InABox.Core
|
|
|
{
|
|
|
table.LoadColumns(typeof(TType));
|
|
|
}
|
|
|
- _tables[name] = new DataModelTable(typeof(TType), table, isdefault, filter, columns, shouldLoad);
|
|
|
+ _tables[name] = new DataModelTable(typeof(TType), table, isdefault, filter, columns, sort, shouldLoad);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void AddChildTable<TParent, TChild>(Expression<Func<TParent, object>> parentcolumn, Expression<Func<TChild, object>> childcolumn,
|
|
|
- Filter<TChild>? filter = null, Columns<TChild>? columns = null, bool isdefault = false, string? parentalias = null, string? childalias = null)
|
|
|
+ Filter<TChild>? filter = null, Columns<TChild>? columns = null, SortOrder<TChild>? sort = null, bool isdefault = false, string? parentalias = null, string? childalias = null)
|
|
|
{
|
|
|
CheckTable<TParent>(parentalias);
|
|
|
- AddTable(filter, columns, isdefault, childalias);
|
|
|
+ AddTable(filter, columns, sort, isdefault, childalias);
|
|
|
LinkTable(parentcolumn, childcolumn, parentalias, childalias, false);
|
|
|
}
|
|
|
|
|
|
public void AddLookupTable<TSource, TLookup>(Expression<Func<TSource, object>> sourcecolumn, Expression<Func<TLookup, object>> lookupcolumn,
|
|
|
- Filter<TLookup>? filter = null, Columns<TLookup>? columns = null, bool isdefault = false,
|
|
|
+ Filter<TLookup>? filter = null, Columns<TLookup>? columns = null, SortOrder<TLookup>? sort = null, bool isdefault = false,
|
|
|
string? sourcealias = null, string? lookupalias = null)
|
|
|
{
|
|
|
CheckTable<TSource>(sourcealias);
|
|
|
- AddTable(filter, columns, isdefault, lookupalias);
|
|
|
+ AddTable(filter, columns, sort, isdefault, lookupalias);
|
|
|
LinkTable(sourcecolumn, lookupcolumn, sourcealias, lookupalias, true);
|
|
|
}
|
|
|
|
|
@@ -664,6 +686,17 @@ namespace InABox.Core
|
|
|
var table = GetDataModelTable(alias);
|
|
|
return table.Columns;
|
|
|
}
|
|
|
+
|
|
|
+ public SortOrder<TType>? GetSortOrder<TType>(string? alias = null)
|
|
|
+ {
|
|
|
+ var table = GetDataModelTable<TType>(alias);
|
|
|
+ return table.Sort as SortOrder<TType>;
|
|
|
+ }
|
|
|
+ public ISortOrder? GetSortOrder(string alias)
|
|
|
+ {
|
|
|
+ var table = GetDataModelTable(alias);
|
|
|
+ return table.Sort;
|
|
|
+ }
|
|
|
|
|
|
[Obsolete("Use SetColumns instead")]
|
|
|
public void SetTableColumns<TType>(Columns<TType> columns, string? alias = null) => SetColumns(columns, alias);
|
|
@@ -679,6 +712,12 @@ namespace InABox.Core
|
|
|
var table = GetDataModelTable<TType>(alias);
|
|
|
table.Columns = columns;
|
|
|
}
|
|
|
+
|
|
|
+ public void SetSortOrder<TType>(SortOrder<TType>? sort, string? alias = null)
|
|
|
+ {
|
|
|
+ var table = GetDataModelTable<TType>(alias);
|
|
|
+ table.Sort = sort;
|
|
|
+ }
|
|
|
|
|
|
public void SetIsDefault<TType>(bool isDefault, string? alias = null)
|
|
|
{
|
|
@@ -760,7 +799,7 @@ namespace InABox.Core
|
|
|
Columns = columns;
|
|
|
Sort = sort;
|
|
|
|
|
|
- AddTable(filter, columns, true);
|
|
|
+ AddTable(filter, columns, sort, true);
|
|
|
AddChildTable<T, AuditTrail>(x => x.ID, x => x.EntityID);
|
|
|
}
|
|
|
|