Hiding menu option according to loan type

Asked

Viewed 80 times

0

Good afternoon, I am developing a registration system with Angularjs and C#, when registering a new user there are two types of users to choose, administrator and librarian, being administrator type 1 and librarian type 2. and a menu with the following options: condominium, book, resident and user, when a user of the type librarian log in I want the condominium option not to be present in the menu, I have already created a method for this, but I would like to know how to use it along with the menu html file

Method code:

public void UserType(string usuario)
{
    var db = new CRMEntities();
    object user;

    try
    {
        user = db.Usuario.Where(p => p.usuario1 == usuario).FirstOrDefault();
    }
    catch (Exception ex)
    {
        user = null;
    }

    var returnJson = "";

    if (user == null)
        returnJson = JsonConvert.SerializeObject(null);
    else
        returnJson = JsonConvert.SerializeObject(((Usuario)user).grupoUsuario);

    ReturnJson(returnJson);
}

Menu code:

<ul class="nav" id="side-menu">
    <li>
            <a href="#!/"><span class="nav-label">Painel</span><span class="fa arrow"></span> </a>
    </li>   
    <li>
        <a href="#"><span class="nav-label">Cadastro</span><span class="fa arrow"></span> </a>
        <ul class="nav nav-second-level">
            <li><a href="#!/condominio">Condom&iacute;nio</a></li>
            <li><a href="#!/livro">Livro</a></li>
            <li><a href="#!/morador">Morador</a></li>
            <li><a href="#!/usuario">Usu&aacute;rio</a></li>
        </ul>
    </li>
</ul>

<script>
    $(document).ready(function () {
        $('#side-menu').metisMenu();
    });
</script>
  • 1

    Pass the information to your model at AngularJS and uses the directive ng-show

1 answer

0

Let’s assume that your menu page is composed of a component, controller, html and a .sass. For this case, the name vm will be the controllerAs of its component.

On your controller, you should have a function that checks whether the user is librarian type or not. Let’s call this function verificarBibliotecario(). If you’re a librarian, go back true, if not, return false.

Thus, it is easy to 'hide' the 'Condominium' option from the initial menu. To do this, you can use the directive ng-show in your html:

<li ng-show="!vm.verificarBibliotecario()"><a href="#!/condominio">Condom&iacute;nio</a></li>

Thus, all users who are not librarians will be able to see the menu option, while a librarian will not have this option available.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.