This commit is contained in:
@@ -67,6 +67,26 @@ namespace AyaNova.Biz
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//SET SORT
|
||||
//
|
||||
|
||||
internal async Task<bool> SetSort(AyaNova.Models.DataListSortRequest newObject)
|
||||
{
|
||||
//Get the current column view (in an updateable manner) and update it's sort property and save
|
||||
var dbObject = await ct.DataListColumnView.SingleOrDefaultAsync(z => z.UserId == UserId && z.ListKey == newObject.ListKey);
|
||||
if (dbObject == null)
|
||||
dbObject = await CreateDefaultColumnView(newObject.ListKey);
|
||||
//convert arrays to proper format for saving
|
||||
Dictionary<string, string> newSort = new Dictionary<string, string>();
|
||||
for (int x = 0; x < newObject.sortBy.Length; x++)
|
||||
newSort.Add(newObject.sortBy[x], (newObject.sortDesc[x] ? "-" : "+"));
|
||||
dbObject.Sort = JsonConvert.SerializeObject(newSort);
|
||||
//columnview is always replace
|
||||
await ct.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -79,21 +99,28 @@ namespace AyaNova.Biz
|
||||
var ret = await ct.DataListColumnView.AsNoTracking().SingleOrDefaultAsync(z => z.UserId == userId && z.ListKey == listKey);
|
||||
if (ret == null && createDefaultIfNecessary)
|
||||
{
|
||||
if (!DataListFactory.ListKeyIsValid(listKey))
|
||||
{
|
||||
throw new System.ArgumentOutOfRangeException($"ListKey '{listKey}' is not a valid DataListKey");
|
||||
}
|
||||
ret = new DataListColumnView();
|
||||
ret.UserId = UserId;
|
||||
ret.ListKey = listKey;
|
||||
var dataList = DataListFactory.GetAyaDataList(listKey);
|
||||
ret.Columns = JsonConvert.SerializeObject(dataList.DefaultColumns);
|
||||
ret.Sort = JsonConvert.SerializeObject(dataList.DefaultSortBy);
|
||||
return await CreateAsync(ret);
|
||||
return await CreateDefaultColumnView(listKey);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
internal async Task<DataListColumnView> CreateDefaultColumnView(string listKey)
|
||||
{
|
||||
if (!DataListFactory.ListKeyIsValid(listKey))
|
||||
{
|
||||
throw new System.ArgumentOutOfRangeException($"ListKey '{listKey}' is not a valid DataListKey");
|
||||
}
|
||||
var ret = new DataListColumnView();
|
||||
ret.UserId = UserId;
|
||||
ret.ListKey = listKey;
|
||||
var dataList = DataListFactory.GetAyaDataList(listKey);
|
||||
ret.Columns = JsonConvert.SerializeObject(dataList.DefaultColumns);
|
||||
ret.Sort = JsonConvert.SerializeObject(dataList.DefaultSortBy);
|
||||
return await CreateAsync(ret);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user