This commit is contained in:
2018-12-03 19:12:35 +00:00
parent 1a90226002
commit 51941a958e
10 changed files with 270 additions and 65 deletions

View File

@@ -18,9 +18,13 @@ namespace AyaNova.Api.ControllerHelpers
[Range(1, MaxPageSize, ErrorMessage = "Limit must be greater than 0 and less than 100.")]
public int? Limit { get; set; }
public string Sort {get;set;}
public bool? Asc {get;set;}
public string Sort { get; set; }
public bool? Asc { get; set; }
//Data filter id to use with this list query
//0 or less means no filter
public long DataFilterId { get; set; }
}

View File

@@ -98,7 +98,7 @@ namespace AyaNova
bool LOG_SENSITIVE_DATA = false;
#if (DEBUG)
//LOG_SENSITIVE_DATA = true;
LOG_SENSITIVE_DATA = true;
#endif

View File

@@ -1,22 +0,0 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using AyaNova.Models;
using Newtonsoft.Json.Linq;
namespace AyaNova.Biz
{
/// <summary>
/// Interface for biz objects that support list filtering
/// </summary>
internal interface IFilterableObject
{
//FILTEROPTIONS COLLECTION
FilterOptions FilterOptions { get; }
}
}

View File

@@ -12,7 +12,7 @@ using System.Collections.Generic;
namespace AyaNova.Biz
{
internal class WidgetBiz : BizObject, IJobObject
{
public static FilterOptions FilterOptions(long localizeToLocaleId = 0)
@@ -153,14 +153,39 @@ namespace AyaNova.Biz
internal async Task<ApiPagedResponse<Widget>> GetManyAsync(IUrlHelper Url, string routeName, PagingOptions pagingOptions)
{
//TODO: build a query, run it outside of Entity Framework directly and return the results in models?!
//Or can ef accept a query with criteria
//https://docs.microsoft.com/en-us/ef/core/querying/raw-sql
//If no datafilter then it can just run this regular code which already works, I think?
//no, order by is brokeh
pagingOptions.Offset = pagingOptions.Offset ?? PagingOptions.DefaultOffset;
pagingOptions.Limit = pagingOptions.Limit ?? PagingOptions.DefaultLimit;
// var items = await ct.Widget
// .OrderBy(m => m.Id)
// .Skip(pagingOptions.Offset.Value)
// .Take(pagingOptions.Limit.Value)
// .ToArrayAsync();
//BUILD THE QUERY
//base query
var q = "SELECT *, xmin FROM AWIDGET ";
//BUILD WHERE AND APPEND IT
//BUILD ORDER BY AND APPEND IT
var items = await ct.Widget
.OrderBy(m => m.Id)
.Skip(pagingOptions.Offset.Value)
.Take(pagingOptions.Limit.Value)
.ToArrayAsync();
.AsNoTracking()
.FromSql(q)
.Skip(pagingOptions.Offset.Value)
.Take(pagingOptions.Limit.Value)
.ToArrayAsync();
var totalRecordCount = await ct.Widget.CountAsync();
var pageLinks = new PaginationLinkBuilder(Url, routeName, null, pagingOptions, totalRecordCount).PagingLinksObject();
@@ -314,11 +339,11 @@ namespace AyaNova.Biz
//run validation and biz rules
if (isNew)
{
//NEW widgets must be active
if (inObj.Active == null || ((bool)inObj.Active) == false)
{
AddError(ValidationErrorType.InvalidValue, "Active", "New widget must be active");
}
// //NEW widgets must be active
// if (inObj.Active == null || ((bool)inObj.Active) == false)
// {
// AddError(ValidationErrorType.InvalidValue, "Active", "New widget must be active");
// }
}
//OwnerId required