Hiding menu option according to user type

0

Good afternoon, I'm 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 librarian type user logs that the condominium option is not present in the menu, I have already created a method for this, however I would like to know how to use it together with the html menu

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>
    
asked by anonymous 11.07.2018 / 20:23

1 answer

0

Let's assume that your menu page consists of a component, driver, html, and .sass. For this case, the vm name will be the controllerAs of your component.

In your controller, you should have a function that checks whether the user is a librarian type or not. Let's call this function verificarBibliotecario() . If you are a librarian, return true , otherwise, return false .

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

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

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

    
17.07.2018 / 10:41