0

I was wondering if anybody could point me in the right direction.

I have a log in screen, i have two sets of users.. Suppliers and Admins.. I wanted to make a pop up screen pop up if a supplier logs in... (This will be so they can sign a declaration with a radio button)so before diverting into the backend, then they must accept the declaration. I do not want the pop up to show if they are an admin user.

1 Answers1

1

I am assuming you are doing this with Razor? I'm also assuming you are using Identity to handle your authentication.

If that's the case you should see this answer first: https://stackoverflow.com/a/45675054/6709649

Get your user's roles with this code:

    var user = await _userManager.FindByNameAsync(User.Identity.Name);
    //Return true if any of the found roles are equal to "Supplier"
    bool isSupplier = await _userManager.GetRoles(user.Id).Any(x => x == "Supplier");

From there you can create a flag on the model you are passing into the razor view:

public class MyViewModel{

  public IsSupplier { get; set; }
  ...

}

And then set MyViewModel.IsSupplier = isSupplier that you found above. In your razor view you can then use a simple if statement to detect whether you show an ajax popup or not:

@if(Model.IsSupplier){
  <!-- Some HTML here to show the popup -->
}
dionm
  • 43
  • 4