public async Task<IEnumerable<dynamic>> GetWhereAsync(long pageNumber, List<Filter> filters)
{
if (string.IsNullOrWhiteSpace(this.Database))
{
return null;
}
if (!this.SkipValidation)
{
if (!this.Validated)
{
await this.ValidateAsync(AccessTypeEnum.Read, this.LoginId, this.Database, false).ConfigureAwait(false);
}
if (!this.HasAccess)
{
Log.Information("Access to Page #{Page} of the filtered entity \"Filter\" was denied to the user with Login ID {LoginId}. Filters: {Filters}.", pageNumber, this.LoginId, filters);
throw new UnauthorizedException("Access is denied.");
}
}
long offset = (pageNumber - 1) * 50;
var sql = new Sql("SELECT * FROM config.filters WHERE 1 = 1");
FilterManager.AddFilters(ref sql, new Filter(), filters);
sql.OrderBy("filter_id");
if (pageNumber > 0)
{
sql.Append(FrapidDbServer.AddOffset(this.Database, "@0"), offset);
sql.Append(FrapidDbServer.AddLimit(this.Database, "@0"), 50);
}
return await Factory.GetAsync<dynamic>(this.Database, sql).ConfigureAwait(false);
}