Frapid.WebApi.DataAccess.FilterRepository.RemoveDefaultAsync C# (CSharp) Method

RemoveDefaultAsync() public method

public RemoveDefaultAsync ( string objectName ) : System.Threading.Tasks.Task
objectName string
return System.Threading.Tasks.Task
        public async Task RemoveDefaultAsync(string objectName)
        {
            if (!this.SkipValidation)
            {
                if (!this.Validated)
                {
                    await this.ValidateAsync(AccessTypeEnum.CreateFilter, this.LoginId, this.Database, false).ConfigureAwait(false);
                }

                if (!this.HasAccess)
                {
                    Log.Information("Access to delete default filter for {ObjectName} was denied to the user with Login ID {LoginId}.", objectName, this.LoginId);
                    throw new UnauthorizedException("Access is denied.");
                }
            }

            const string sql = "UPDATE config.filters SET is_default=false WHERE object_name=@0;";
            await Factory.NonQueryAsync(this.Database, sql, objectName).ConfigureAwait(false);
        }
    }

Usage Example

Ejemplo n.º 1
0
        public async Task RemoveDefaultAsync(string objectName)
        {
            try
            {
                var repository = new FilterRepository(this.AppUser.Tenant, this.AppUser.LoginId, this.AppUser.UserId);
                await repository.RemoveDefaultAsync(objectName).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
        }