Want to check admin login or not

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 лет назад
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
6 лет назад
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  
    }
6 лет назад
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  
    }
6 лет назад
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
6 лет назад
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...'
6 лет назад
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
6 лет назад
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.