public async Task <IEnumerable <dynamic> > GetPaginatedResultAsync(long pageNumber) { 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 entity \"{this.FullyQualifiedObjectName}\" was denied to the user with Login ID {this.LoginId}."); throw new UnauthorizedException(Resources.AccessIsDenied); } } long offset = (pageNumber - 1) * Config.GetPageSize(this.Database); //"SELECT * FROM {this.FullyQualifiedObjectName} //ORDER BY {this.PrimaryKey} LIMIT PageSize OFFSET @0;"; var sql = new Sql($"SELECT * FROM {this.FullyQualifiedObjectName}"); sql.OrderBy(this.PrimaryKey); sql.Append(FrapidDbServer.AddOffset(this.Database, "@0"), offset); sql.Append(FrapidDbServer.AddLimit(this.Database, "@0"), Config.GetPageSize(this.Database)); return(await Factory.GetAsync <dynamic>(this.Database, sql).ConfigureAwait(false)); }
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(Resources.AccessIsDenied); } } long offset = (pageNumber - 1) * Config.GetPageSize(this.Database); var sql = new Sql($"SELECT * FROM {this.FullyQualifiedObjectName} WHERE 1 = 1"); FilterManager.AddFilters(ref sql, filters); sql.OrderBy("1"); if (pageNumber > 0) { sql.Append(FrapidDbServer.AddOffset(this.Database, "@0"), offset); sql.Append(FrapidDbServer.AddLimit(this.Database, "@0"), Config.GetPageSize(this.Database)); } return(await Factory.GetAsync <dynamic>(this.Database, sql).ConfigureAwait(false)); }
public async Task <IEnumerable <dynamic> > GetPaginatedResultAsync(long pageNumber) { 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 entity \"{this.FullyQualifiedObjectName}\" was denied to the user with Login ID {this.LoginId}."); throw new UnauthorizedException("Access is denied."); } } long offset = (pageNumber - 1) * PageSize; string sql = $"SELECT * FROM {this.FullyQualifiedObjectName} WHERE deleted=@0 ORDER BY {this.PrimaryKey}"; sql += FrapidDbServer.AddOffset(this.Database, "@1"); sql += FrapidDbServer.AddLimit(this.Database, PageSize.ToString()); return(await Factory.GetAsync <dynamic>(this.Database, sql, false, offset).ConfigureAwait(false)); }
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)); }
public async Task <dynamic> GetLastAsync() { 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 the get the last record of entity \"{this.FullyQualifiedObjectName}\" was denied to the user with Login ID {this.LoginId}"); throw new UnauthorizedException("Access is denied."); } } //$"SELECT * FROM {this.FullyQualifiedObjectName} //ORDER BY {this.PrimaryKey} DESC LIMIT 1;"; var sql = new Sql($"SELECT * FROM {this.FullyQualifiedObjectName} WHERE deleted=@0", false); sql.Append($"ORDER BY {this.PrimaryKey} DESC"); sql.Append(FrapidDbServer.AddOffset(this.Database, "@0"), 0); sql.Append(FrapidDbServer.AddLimit(this.Database, "@0"), 1); return((await Factory.GetAsync <dynamic>(this.Database, sql).ConfigureAwait(false)).FirstOrDefault()); }
public async Task <IEnumerable <dynamic> > GetPaginatedResultAsync() { 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 the first page of the entity \"{this.FullyQualifiedObjectName}\" was denied to the user with Login ID {this.LoginId}."); throw new UnauthorizedException("Access is denied."); } } var sql = new Sql($"SELECT * FROM {this.FullyQualifiedObjectName} WHERE deleted=@0", false); sql.OrderBy(this.PrimaryKey); sql.Append(FrapidDbServer.AddOffset(this.Database, "@0"), 0); sql.Append(FrapidDbServer.AddLimit(this.Database, "@0"), PageSize); return(await Factory.GetAsync <dynamic>(this.Database, sql).ConfigureAwait(false)); }
public async Task <dynamic> GetNextAsync(object primaryKey) { 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 the get the next entity of \"{this.FullyQualifiedObjectName}\" by \"{this.PrimaryKey}\" with value {primaryKey} was denied to the user with Login ID {this.LoginId}"); throw new UnauthorizedException(Resources.AccessIsDenied); } } //$"SELECT * FROM {this.FullyQualifiedObjectName} WHERE {this.PrimaryKey} > @0 //ORDER BY {this.PrimaryKey} LIMIT 1;"; var sql = new Sql($"SELECT * FROM {this.FullyQualifiedObjectName} WHERE deleted=@0", false); sql.And($"{this.PrimaryKey} > @0", primaryKey); sql.OrderBy(this.PrimaryKey); sql.Append(FrapidDbServer.AddOffset(this.Database, "@0"), 0); sql.Append(FrapidDbServer.AddLimit(this.Database, "@0"), 1); return((await Factory.GetAsync <dynamic>(this.Database, sql).ConfigureAwait(false)).FirstOrDefault()); }
public IEnumerable <dynamic> GetPaginatedResult(long pageNumber) { if (string.IsNullOrWhiteSpace(this.Database)) { return(null); } if (!this.SkipValidation) { if (!this.Validated) { this.Validate(AccessTypeEnum.Read, this.LoginId, this.Database, false); } if (!this.HasAccess) { Log.Information( $"Access to Page #{pageNumber} of the entity \"{this.FullyQualifiedObjectName}\" was denied to the user with Login ID {this.LoginId}."); throw new UnauthorizedException("Access is denied."); } } long offset = (pageNumber - 1) * 50; string sql = $"SELECT * FROM {this.FullyQualifiedObjectName} ORDER BY {this.PrimaryKey}"; sql += FrapidDbServer.AddOffset("@0"); sql += FrapidDbServer.AddLimit("50"); return(Factory.Get <dynamic>(this.Database, sql, offset)); }
public async Task <IEnumerable <dynamic> > GetFilteredAsync(long pageNumber, string filterName) { 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}. Filter: {filterName}."); throw new UnauthorizedException(Resources.AccessIsDenied); } } var filters = await this.GetFiltersAsync(this.Database, filterName).ConfigureAwait(false); long offset = (pageNumber - 1) * Config.GetPageSize(this.Database); var sql = new Sql($"SELECT * FROM {this.FullyQualifiedObjectName} WHERE deleted = @0", false); FilterManager.AddFilters(ref sql, filters.ToList()); 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"), Config.GetPageSize(this.Database)); } try { return(await Factory.GetAsync <dynamic>(this.Database, sql).ConfigureAwait(false)); } catch (DbException ex) { Log.Error(ex.Message); throw new DataAccessException(this.Database, ex.Message, ex); } }
public IEnumerable <dynamic> GetFiltered(long pageNumber, string filterName) { if (string.IsNullOrWhiteSpace(this.Database)) { return(null); } if (!this.SkipValidation) { if (!this.Validated) { this.Validate(AccessTypeEnum.Read, this.LoginId, this.Database, 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}. Filter: {filterName}."); throw new UnauthorizedException("Access is denied."); } } var filters = this.GetFilters(this.Database, filterName); long offset = (pageNumber - 1) * 50; var sql = Sql.Builder.Append($"SELECT * FROM {this.FullyQualifiedObjectName} WHERE 1 = 1"); FilterManager.AddFilters(ref sql, filters); if (!string.IsNullOrWhiteSpace(this.PrimaryKey)) { sql.OrderBy(this.PrimaryKey); } if (pageNumber > 0) { sql.Append(FrapidDbServer.AddOffset("@0"), offset); sql.Append(FrapidDbServer.AddLimit("@0"), 50); } return(Factory.Get <dynamic>(this.Database, sql)); }
public async Task <dynamic> GetFirstAsync() { 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 the get the first record of entity \"{this.FullyQualifiedObjectName}\" was denied to the user with Login ID {this.LoginId}"); throw new UnauthorizedException(Resources.AccessIsDenied); } } var sql = new Sql($"SELECT * FROM {this.FullyQualifiedObjectName} WHERE deleted=@0", false); sql.OrderBy(this.PrimaryKey); sql.Append(FrapidDbServer.AddOffset(this.Database, "@0"), 0); sql.Append(FrapidDbServer.AddLimit(this.Database, "@0"), 1); try { return((await Factory.GetAsync <dynamic>(this.Database, sql).ConfigureAwait(false)).FirstOrDefault()); } catch (DbException ex) { Log.Error(ex.Message); throw new DataAccessException(this.Database, ex.Message, ex); } }