5 Answer(s)
-
0
-
0
I tried that also, but still it shows me null.
using Org.BouncyCastle.Math.EC.Rfc7748; using Pulsar.Dashboard.Account.Dto; using Pulsar.Dashboard.PulsarModel; using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Text; using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.Domain.Repositories; namespace Pulsar.Dashboard.Account { public class AccountInfoAppService : ApplicationService, IAccountInfoAppService { private readonly IRepository<UserAccountsMapping, Guid> _accountRepository; public AccountInfoAppService(IRepository<UserAccountsMapping, Guid> accountRepository ) { _accountRepository = accountRepository; } public List<string> GetAccId() { var list = _accountRepository .Where(p => p.UserId == CurrentUser.Id.ToString()).Select(x => x.AccountId) .ToList(); return list; } } }
Here is the code for MenuContributor.cs where i want to use the AccountInfoAppService.
Is there another way to do this ?
Thanks
-
0
hi @kirtik
Can you share your full code?
-
0
Basically our issue is : we are unable to call applicationService which is created in Application project. We have created a menu in DashBoarMenuContributor.cs now we want to call the method from the appservice as show in the shared image repository returns null value we are unable to get current user in DashboardContributor.cs file
I am sharing the AppService and the MenuContributor files code here :
using System.Linq; using System.Text; using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.Domain.Repositories; namespace Pulsar.Dashboard.Account { public class AccountInfoAppService : ApplicationService, IAccountInfoAppService { private readonly IRepository<UserAccountsMapping, Guid> _accountRepository; public AccountInfoAppService(IRepository<UserAccountsMapping, Guid> accountRepository ) { _accountRepository = accountRepository; } public List<string> GetAccId() { var list = _accountRepository .Where(p => p.UserId == CurrentUser.Id.ToString()).Select(x => x.AccountId) .ToList(); return list; } } }
DashboardMenuContributor.cs
using Abp.Domain.Repositories; using Pulsar.Dashboard.Account; using Pulsar.Dashboard.Localization; using Pulsar.Dashboard.Permissions; using Pulsar.Dashboard.PulsarEnums; using Pulsar.Dashboard.PulsarModel; using Pulsar.Dashboard.Users; using System; using System.Threading.Tasks; using Volo.Abp.Account; using Volo.Abp.AuditLogging.Web.Navigation; using Volo.Abp.Domain.Repositories; using Volo.Abp.Identity.Web.Navigation; using Volo.Abp.IdentityServer.Web.Navigation; using Volo.Abp.LanguageManagement.Navigation; using Volo.Abp.SettingManagement.Web.Navigation; using Volo.Abp.TextTemplateManagement.Web.Navigation; using Volo.Abp.UI.Navigation; using Volo.Abp.Users; using Volo.Saas.Host.Navigation; namespace Pulsar.Dashboard.Web.Menus { public class DashboardMenuContributor : IMenuContributor { private readonly IAccountInfoAppService _accountAppService; public async Task ConfigureMenuAsync(MenuConfigurationContext context) { if (context.Menu.Name == StandardMenus.Main) { await ConfigureMainMenuAsync(context); } } private async Task ConfigureMainMenuAsync(MenuConfigurationContext context) { var l = context.GetLocalizer<DashboardResource>(); //Home context.Menu.AddItem( new ApplicationMenuItem( DashboardMenus.Home, l["Menu:Home"], "~/", icon: "fa fa-home", order: 1 ) ); context.Menu.AddItem( new ApplicationMenuItem( DashboardMenus.Trades, l["Menu:Trades"], "~/", icon: "fa fa-home", order: 2 ) ); //Trades context.Menu.AddItem( new ApplicationMenuItem( DashboardMenus.Brokers, l["Menu:Brokers"], "~/", icon: "fa fa-home", order: 3 ) ); if (await context.IsGrantedAsync(DashboardPermissions.Dashboard.Host)) { //HostDashboard context.Menu.AddItem( new ApplicationMenuItem( DashboardMenus.HostDashboard, l["Menu:Dashboard"], "~/HostDashboard", icon: "fa fa-line-chart", order: 3 ) ); } if (await context.IsGrantedAsync(DashboardPermissions.Dashboard.Tenant)) { //TenantDashboard var dashboardMenu = context.Menu.AddItem( new ApplicationMenuItem( DashboardMenus.TenantDashboard, l["Menu:Dashboard"], "~/Dashboard", icon: "fa fa-line-chart", order: 3 ) ); var result = _accountAppService.GetAccId(); Console.WriteLine(result); } //Administration var administration = context.Menu.GetAdministration(); administration.Order = 4; //Administration->Saas administration.SetSubItemOrder(SaasHostMenuNames.GroupName, 1); //Administration->Identity administration.SetSubItemOrder(IdentityMenuNames.GroupName, 2); //Administration->Identity Server administration.SetSubItemOrder(AbpIdentityServerMenuNames.GroupName, 3); //Administration->Language Management administration.SetSubItemOrder(LanguageManagementMenuNames.GroupName, 4); //Administration->Text Template Management administration.SetSubItemOrder(TextTemplateManagementMainMenuNames.GroupName, 5); //Administration->Audit Logs administration.SetSubItemOrder(AbpAuditLoggingMainMenuNames.GroupName, 6); //Administration->Settings administration.SetSubItemOrder(SettingManagementMenuNames.GroupName, 7); } } }
Please check where _accountAppService.GetAccId(); is called.
Thanks...
-
0
hi
Your
_accountAppService
in theDashboardMenuContributor
class hasn't been initial.You can try to get your service through
context.ServiceProvider.GetService<YourService>();
of course you can get other services.