Starts in:
2 DAYS
16 HRS
53 MIN
14 SEC
Starts in:
2 D
16 H
53 M
14 S
Open Closed

Add a new data filter #8247


User avatar
0
Spospisil created
  • ABP Framework version: v7.3.0
  • UI Type: Blazor WASM
  • Database System: EF Core (PostgreSQL, etc..)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes

I need to implement a new datafilter called ICompany which will hold a guid for the current company a user has chosen. This filter needs to be used across several abp modules each with their own DBContext. What's the best way to implement this given my use case and how would I go about setting the CompanyId for this filter when a user changes the current company guid they are wanting to filter the data with.

public interface ICompany { Guid CompanyId { get; set; } }

Yes, I have look at the following documentation (https://abp.io/docs/latest/framework/infrastructure/data-filtering#defining-custom-filters), but this implies I need to do this for every DBContext in every module I create which seems like too much to accomplish this.


20 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can check this article https://abp.io/community/articles/switching-between-organization-units-i5tokpzt

  • User Avatar
    0
    Spospisil created

    Hi,

    I appreciate this link and it contains some helpful information however, I still do not see how this would be applied to all my DBContext implementations across all my modules as I indicated in my initial message.

  • User Avatar
    0
    Spospisil created

    Hi,

    Would I use the method in this link (https://abp.io/docs/latest/framework/data/entity-framework-core#replacedbcontext-attribute) to achieve my requirement of having all the other DBContext objects, across all my modules in my solution applying this new data filter?

  • User Avatar
    0
    Spospisil created

    Hi,

    Also what's confusing to me is that the link you provided is not specific to a Blazor WASM project, so it's confusing to know which of the classes mentioned in the link your provided go into which project in our tiered solution structure. As a reminder we are running a Blazor WASM project hosted in the abp generated 'public' website module. If you could also demonstrate where these classes go in terms of which project.

    Is it possible you can generate a sample project of how to do what I originally asked for but using a Blazor WASM project?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share your app DbContext class?

    This is the feature in EF Core, which has nothing to do with front-end UI(Blazor-WASM)

  • User Avatar
    0
    Spospisil created

    This is what the current DBContext class is for my blazor app. I have not implemented the suggested changes from your post the details them out, but I don't want to have to make this change to all my other ABP generated modules in my solution. I asked previously if those other DB contexts ( ILanguageManagementDbContext, ISystemMaintenanceDbContext, IReportQuickDesignerDbContext and ISecurityDbContext) also need these changes or if just having the [ReplaceDBContext] negates that and you have not responded directly to that question.

    I also asked if you could detail what projects each of the proposed changes in your post (https://abp.io/community/articles/switching-between-organization-units-i5tokpzt) as it's not clear which projects they should go so the project compiles correctly.

    Again seeing an actual example of a tiered blazor WASM solution referencing an ABP Generated Module (with it's own DBContext) being referenced by this blazor wasm project would be helpful.

    
    namespace CFDataSystems.StructureCloud.EntityFrameworkCore;
    
    [ConnectionStringName(StructureCloudDbProperties.HostConnectionStringName)]
    [ReplaceDbContext(typeof(IIdentityProDbContext))]
    [ReplaceDbContext(typeof(IIdentityDbContext))]
    [ReplaceDbContext(typeof(ISaasDbContext))]
    [ReplaceDbContext(typeof(ILanguageManagementDbContext))]
    [ReplaceDbContext(typeof(ISystemMaintenanceDbContext))]
    [ReplaceDbContext(typeof(IReportQuickDesignerDbContext))]
    [ReplaceDbContext(typeof(ISecurityDbContext))]
    public class StructureCloudDbContext : AbpDbContext<StructureCloudDbContext>,
        IStructureCloudDbContext,
        IIdentityProDbContext,
        IIdentityDbContext,
        ISaasDbContext,
        ILanguageManagementDbContext,
        ISystemMaintenanceDbContext,
        IReportQuickDesignerDbContext,
        ISecurityDbContext
    {
    
        //Custom Tables
        public DbSet<TenantInformation> TenantInformation { get; set; }
    
        public DbSet<Screen> Screens { get; set; }
    
        public DbSet<UserDashboard> UserDashboards { get; set; }
        public DbSet<UserInformation> UserInformation { get; set; }
        public DbSet<UserLaunch> UserLaunch { get; set; }
        public DbSet<Template> Template { get; set; }
    
    	//Saas Tables
    	public DbSet<Tenant> Tenants { get; set; }
        public DbSet<Edition> Editions { get; set; }
        public DbSet<TenantConnectionString> TenantConnectionStrings { get; set; }
    
        //Itentity Tables
        public DbSet<IdentityUser> Users { get; set; }
        public DbSet<IdentityRole> Roles { get; set; }
        public DbSet<IdentityClaimType> ClaimTypes { get; set; }
        public DbSet<OrganizationUnit> OrganizationUnits { get; set; }
        public DbSet<IdentitySecurityLog> SecurityLogs { get; set; }
        public DbSet<IdentityLinkUser> LinkUsers { get; set; }
        public DbSet<IdentityUserDelegation> UserDelegations { get; }
    
        //Language tables
        public DbSet<Language> Languages { get; set; }
        public DbSet<LanguageText> LanguageTexts { get; set; }
        public DbSet<LocalizationResourceRecord> LocalizationResources { get; set; }
        public DbSet<LocalizationTextRecord> LocalizationTexts { get; set; }
    
        //System Maintenance Tables
        public DbSet<SystemMaintenance.Domain.Attributes.Attribute> Attribute { get; set; }
        public DbSet<DataView> Views { get; set; }
        public DbSet<ViewJoin> ViewJoins { get; set; }
        public DbSet<JoinField> JoinFields { get; set; }
        public DbSet<CalculatedField> CalculatedFields { get; set; }
        public DbSet<ReferencedField> ReferencedFields { get; set; }
        public DbSet<DataType> DataTypes { get; set; }
        public DbSet<DataSourceQuery> DataSourceQueries { get; set; }
        public DbSet<DataSourceHeader> DataSourceHeaders { get; set; }
        public DbSet<DataSourceDetail> DataSourceDetails { get; set; }
        public DbSet<DataSourceProcedure> DataSourceProcedures { get; set; }
        public DbSet<Application> Applications { get; set; }
        public DbSet<Procedure> Procedures { get; set; }
        public DbSet<MenuGroup> MenuGroups { get; set; }
        public DbSet<RaiqiHeader> RaiqiHeader { get; set; }
        public DbSet<RaiqiDetail> RaiqiDetails { get; set; }
        public DbSet<Parameter> Parameters { get; set; }
        public DbSet<SqlTables> SqlTables { get; set; }
    
        //Security Tables
        public DbSet<SecurityRole> SecurityRoles { get; set; }
        public DbSet<SecurityRoleProcedure> SecurityRoleProcedures { get; set; }
        public DbSet<UserSecurityRole> UserSecurityRoles { get; set; }
        public DbSet<SecurityRoleStructure> SecurityRolesStructure { get; set; }
        public DbSet<SecurityRoleStructureWithProcedures> SecurityRolesStructureWithProcedures { get; set; }
        public DbSet<UserPermissionView> UserPermissions { get; set; }
    
    
        public StructureCloudDbContext(DbContextOptions<StructureCloudDbContext> options)
            : base(options)
        {
        }
        protected override void OnModelCreating(ModelBuilder builder)
        {
            //base.OnModelCreating(builder);
            builder.SetMultiTenancySide(MultiTenancySides.Host);
    
            if (builder.IsHostDatabase())
            {
                ConfigurDatabaseSettings(builder);
            }
    
            builder.HasDefaultSchema("public");
            base.OnModelCreating(builder);
        }
    
        private void ConfigurDatabaseSettings(ModelBuilder builder)
        {
            AbpCommonDbProperties.DbTablePrefix = string.Empty;
            builder.ConfigurePermissionManagement();
            builder.ConfigureSettingManagement();
            builder.ConfigureBackgroundJobs();
            builder.ConfigureIdentityPro();
            builder.ConfigureFeatureManagement();
            builder.ConfigureLanguageManagement();
            builder.ConfigureAuditLogging();
            //PaymentDbProperties.DbTablePrefix = string.Empty;
            //builder.ConfigurePayment();
            builder.ConfigureOpenIddict();
            SaasDbProperties.DbTablePrefix = string.Empty;
            builder.ConfigureSaas();
            TextTemplateManagementDbProperties.DbTablePrefix = string.Empty;
            builder.ConfigureTextTemplateManagement();
            builder.ConfigureBlobStoring();
            builder.ConfigureGdpr();
            //builder.ConfigureCmsKit();
            //builder.ConfigureCmsKitPro();
    
            builder.ConfigureHostTables();
            StructureCloudDbProperties.DbSchema = "structurecloud_settings";
            builder.ConfigureSystemMaintenance();
            builder.ConfigureSecurity();
    
            AccountsPayableDbProperties.DbSchema = "vision";
            builder.ConfigureAccountsPayable();
            AccountsReceivableDbProperties.DbSchema = "vision";  
            builder.ConfigureAccountsReceivable();
            JobCostDbProperties.DbSchema = "vision";
            builder.ConfigureJobCost();
            WorkOrderDbProperties.DbSchema = "vision";
            builder.ConfigureWorkOrders();
            PurchaseOrderDbProperties.DbSchema = "vision";
            builder.ConfigurePurchaseOrders();
    
            builder.ConfigureReportQuickDesigner();
    
        }
    
    
    }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Your StructureCloudDbContext has already replaced some modules.

    You can add your custom data filter in StructureCloudDbContext.

    https://abp.io/docs/latest/framework/infrastructure/data-filtering#entityframework-core

  • User Avatar
    0
    Spospisil created

    I am asking you specific questions and you’re not answering them at all.

    I’ve asked you to detail where the changes such as the interface class goes representing the data filter so that it can be added to domain classes in other tiered modules I’m referencing.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I need to implement a new datafilter called ICompany which will hold a guid for the current company a user has chosen. This filter needs to be used across several abp modules each with their own DBContext. What's the best way to implement this given my use case

    public interface ICompany
    {
        Guid CompanyId { get; set; }
    }
    
    1. Add a new class library and define the ICompany interface.
    2. Use this class library in your modules. eg inherit ICompany in some entities of some modules.
    3. Add your custom data filter in StructureCloudDbContext.(https://abp.io/docs/latest/framework/infrastructure/data-filtering#entityframework-core)
    4. https://abp.io/community/articles/switching-between-organization-units-i5tokpzt

    how would I go about setting the CompanyId for this filter when a user changes the current company guid they are wanting to filter the data with.

    How do your users change their CompanyId? Where do you store the CompanyId? In CurrentUserClaims?

    This article stores the OrganizationId in IDistributedCache and changes it in ASPNET Core middleware

  • User Avatar
    0
    Spospisil created

    Hi,

    Do you have a place where I can share some sample code with you so you can help me determine what the issue is that I'm getting with this?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can create a new GitHub private repository and invite me as a contributor.

    https://github.com/maliming

  • User Avatar
    0
    Spospisil created

    I have given you access to a repository for another issue I'm having while creating this sample project for you.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I have got your project.

    Can you share some steps to show the problem?

    Or what code you don't understand? etc...

    Then I will add a new code.

    Thanks.

  • User Avatar
    0
    Spospisil created

    I created another ticket regarding this sample project. You need to address that one first.

    Run the dbmigrator to create the db and then run the project and you’ll see the error with the blazor iui

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    1. Upgrade all blazorise to 1.5.2

    1. There is no HTTP proxy implement of ICurrentCompanyAppService

  • User Avatar
    0
    Spospisil created

    Frustrated beyond belief with you on this one. The original issue I'm having is with the custom data filter, so I created a new project for you to demonstrate using ABP Studio/ABP Suite. The generated solution Blazor's project does not run (if you ran it you'd see that), so I couldn't even test out the data filter aspect. So you only addressed the things I didn't implement to create a sample for you but you didn't even address anything related to the custom data filter.

    So can I assume in the demo I created for you I've implemented everything correctly with the custom data filter or did you not even look at that part?

    Again I'll mention again to you the generated solution from ABP tools DID NOT RUN after it was generated!!!! So any data filter code and other code I added after that fact I could not test because the base solution (blazor project) does not run!!!!!!

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    ok, I will add some code to make the filter works.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You need to add HttpApi and HttpApi.Client to call the app service in the Blazer Wasm project.

    The code: https://github.com/spospisil/ABPSampleDataFilter/pull/1/

  • User Avatar
    0
    Spospisil created

    Ok, thank you. Now that I can run the project I could see the other things I had missing, but more importantly I can see the custom data filter now running as expected. I will make the changes to my enterprise solution so we can utilize the new custom data filter.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    : )

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06