.NET Core 3.1
Angular
v9.0.1
Hello,
here the scenario, our tenants will have their client login to view their invoices via the app, we created a role "ClientCustomers" for them. we also created 2 new entities as follows:
ClientAccounts: This table will hold the list of accounts and the respectice userid associated with that account (one client can have multiple accounts)
ClientAccountsInvoices: This table hold the invoices details and is linked to the ClientAccounts via ClientAccount.Id.
how can I show the current user, only those records from the ClientAccountsInvoices that belong to him/her?
Thanks,
3 Answer(s)
-
0
Hi hrod761,
I think you can inject into ʻIAbpSessionand get the current user Id through the ʻUserId
property.
When queryingClientAccountsInvoices
, query the corresponding database table through theIQuerable
association.
Fake code:public async Task TestDemoAsync() { var currentUserId = AbpSession.UserId; if (currentUserId == null) { throw new UserFriendlyException("User not login."); } var currentUserAccounts = ClientAccountsRep.GetAll().Where(ca => ca.UserId = currentUserId); var currentUserInvoices = await ClientAccountsInvoicesRep.GetAll() .Join(currentUserAccounts, cai => cai.ClientAccount.Id, ca => ca.UserId, (cai, ca) => cai) .ToListAsync(); var currentUserAccountsList = await currentUserAccounts.ToListAsync(); }
-
1
Thanks for the suggestion, i'll give that a try and report back.
-
0
Hi @hrod761
Please reopen if that doesn't work for you.