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 #{pageNumber} of the filtered entity \"{this.FullyQualifiedObjectName}\" was denied to the user with Login ID {this.LoginId}. Filters: {filters}.");
throw new UnauthorizedException("Access is denied.");
}
}
long offset = (pageNumber - 1)*PageSize;
var sql = new Sql($"SELECT * FROM {this.FullyQualifiedObjectName} WHERE deleted = @0", false);
FilterManager.AddFilters(ref sql, filters);
if (!string.IsNullOrWhiteSpace(this.PrimaryKey))
{
sql.OrderBy(this.PrimaryKey);
}
if (pageNumber > 0)
{
sql.Append(FrapidDbServer.AddOffset(this.Database, "@0"), offset);
sql.Append(FrapidDbServer.AddLimit(this.Database, "@0"), PageSize);
}
return await Factory.GetAsync<dynamic>(this.Database, sql).ConfigureAwait(false);
}