Frapid.WebApi.DataAccess.FormRepository.GetCustomFieldsAsync C# (CSharp) Method

GetCustomFieldsAsync() public method

public GetCustomFieldsAsync ( string resourceId ) : Task>
resourceId string
return Task>
        public async Task<IEnumerable<CustomField>> GetCustomFieldsAsync(string resourceId)
        {
            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 get custom fields for entity \"{this.FullyQualifiedObjectName}\" was denied to the user with Login ID {this.LoginId}");
                    throw new UnauthorizedException("Access is denied.");
                }
            }

            string sql;
            if (string.IsNullOrWhiteSpace(resourceId))
            {
                sql =
                    $"SELECT * FROM config.custom_field_definition_view WHERE table_name='{this.FullyQualifiedObjectName}' ORDER BY field_order;";
                return await Factory.GetAsync<CustomField>(this.Database, sql).ConfigureAwait(false);
            }

            sql = FrapidDbServer.GetProcedureCommand
                (
                    this.Database,
                    "config.get_custom_field_definition",
                    new[]
                    {
                        "@0",
                        "@1"
                    });
            return
                await
                    Factory.GetAsync<CustomField>(this.Database, sql, this.FullyQualifiedObjectName, resourceId)
                        .ConfigureAwait(false);
        }

Usage Example

Esempio n. 1
0
        public async Task<IEnumerable<CustomField>> GetCustomFieldsAsync(string schemaName, string tableName, string resourceId)
        {
            try
            {
                var repository = new FormRepository(schemaName, tableName, this.AppUser.Tenant, this.AppUser.LoginId, this.AppUser.UserId);
                return await repository.GetCustomFieldsAsync(resourceId).ConfigureAwait(false);
            }
            catch(UnauthorizedException)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
            }
            catch(DataAccessException ex)
            {
                throw new HttpResponseException
                    (
                    new HttpResponseMessage
                    {
                        Content = new StringContent(ex.Message),
                        StatusCode = HttpStatusCode.InternalServerError
                    });
            }
#if !DEBUG
            catch
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }
#endif
        }