Want to check admin login or not

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Hace 6 años
Hello.

I want to check if admin is login or not in front end.

I have created one button and by default it will be disabled.

If admin login in front end then only that button will be enabled, so can any one help me how can I check if admin is login or not.

Thanks
Hace 6 años
Please try the bellow code at your RazorView
@using Nop.Core
@using Nop.Core.Infrastructure;


@{

    var _workContext = EngineContext.Current.Resolve<IWorkContext>();
    var isUseradmin = _workContext.CurrentCustomer.IsAdmin();
}

    @if (isUseradmin)
    {
     //do your work  
    }
Hace 6 años
This post by mistake. Same as the first one.

@using Nop.Core
@using Nop.Core.Infrastructure;


@{

    var _workContext = EngineContext.Current.Resolve<IWorkContext>();
    var isUseradmin = _workContext.CurrentCustomer.IsAdmin();
}

    @if (isUseradmin)
    {
     //do your work  
    }
Hace 6 años
pms wrote:
Hello.

I want to check if admin is login or not in front end.

I have created one button and by default it will be disabled.

If admin login in front end then only that button will be enabled, so can any one help me how can I check if admin is login or not.

Thanks


@Thanks Sina

For nop version 4.00 try ==>

@inject IWorkContext workContext

    @if (workContext.CurrentCustomer.IsAdmin())
    {
     //Here write code
    }

//Sohel
Hace 6 años
Hello Sina,

Thanks for reply..I try that but getting following error.

'Custom Does not contain definition for 'isAdmin' and no Extension method 'isAdmin' accepting a first argument of type 'Customer' could be found...'
Hace 6 años
pms wrote:
Hello Sina,

Thanks for reply..I try that but getting following error.

'Custom Does not contain definition for 'isAdmin' and no Extension method 'isAdmin' accepting a first argument of type 'Customer' could be found...'


Try with using the following line

@using Nop.Core.Domain.Customers
Hace 6 años
Yes, it works

Many Thanks for your help..
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.