Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task <ValidationModel> GetMenuRol(string token)
        {
            try {
                FuseNavigationResponse _response = new FuseNavigationResponse();
                var user = _iunitOfWork.UserTokenRepository.FindAllAsync(x => x.Token == token).Result.FirstOrDefault();
                if (user == null)
                {
                    _response.ValidationResults.Add(new ValidationResult("No existe Rol / Usuario", new[] { "GetMenuRol -> no existe Rol / Usuario" }));
                    return(_response);
                }

                //Recuperamos el
                var _userRolNet = _iunitOfWork.NetUserRolesRepository.FindAllAsync(x => x.UserId == user.User_Id).Result.FirstOrDefault();
                _response = await LoadMenuFuseNavigationAsync(new Guid(_userRolNet.RoleId));

                return(_response);
            }
            catch (CError e)
            {
                var jsonModel = JsonConvert.SerializeObject(token);
                throw _errorManager.AddError("Error Get Rol", "GetMenuRol", e, MethodBase.GetCurrentMethod(), jsonModel);
            }
            catch (System.Exception ex)
            {
                var jsonModel = JsonConvert.SerializeObject(token);
                throw _errorManager.AddError("Error Get Rol", "GetMenuRol", ex, MethodBase.GetCurrentMethod(), jsonModel);
            }
        }
Exemplo n.º 2
0
        private async Task <FuseNavigationResponse> LoadMenuFuseNavigationAsync(Guid rol)
        {
            //List<FuseNavigationResponse> menuColection = new List<FuseNavigationResponse>();
            FuseNavigationResponse menu = new FuseNavigationResponse();

            menu.Navigation = new List <FNavigationN1Response>();


            var collectionMenu = await _iunitOfWork.MasterJerarquiaMenusRepository.GetAllAsync();

            var rolmenu = collectionMenu.Where(x => x.UID_PERFIL == rol);
            //Recuperamos los id padres
            var itemspadres = rolmenu.Where(x => x.Nivel == 1 && x.UID_Padre is null);

            foreach (var i1 in itemspadres)
            {
                FNavigationN1Response itemPrimerNivel = new FNavigationN1Response();
                itemPrimerNivel.id        = i1.UID_FUNCTION.ToString();
                itemPrimerNivel.title     = i1.Menu;
                itemPrimerNivel.translate = i1.Menu;
                itemPrimerNivel.type      = "group";
                itemPrimerNivel.icon      = string.IsNullOrEmpty(i1.Icono) ? "" : i1.Icono;
                //Cargamos los hijos de segundo nivel
                var collectionSegundNivel = rolmenu.Where(x => x.UID_Padre == i1.UID_FUNCTION && x.Nivel == 2);
                itemPrimerNivel.children = new List <FNavigationN2Response>();
                foreach (var i2 in collectionSegundNivel)
                {
                    FNavigationN2Response itemSegundoNivel = new FNavigationN2Response();
                    itemSegundoNivel.id        = i2.UID_FUNCTION.ToString();
                    itemSegundoNivel.title     = i2.Menu;
                    itemSegundoNivel.translate = i2.Menu;
                    itemSegundoNivel.icon      = string.IsNullOrEmpty(i2.Icono) ? "" : i2.Icono;
                    if (!string.IsNullOrEmpty(i2.Url))
                    {
                        itemSegundoNivel.type = "item";
                        itemSegundoNivel.url  = i2.Url;
                    }
                    else
                    {
                        itemSegundoNivel.type = "collapsable";
                    }


                    //Cargamos el tercer nivel
                    var collectionTercerNivel = rolmenu.Where(x => x.UID_Padre == i2.UID_FUNCTION && x.Nivel == 3);
                    itemSegundoNivel.children = new List <FNavigationN3Response>();
                    foreach (var i3 in collectionTercerNivel)
                    {
                        FNavigationN3Response item3Nivel = new FNavigationN3Response();
                        item3Nivel.id    = i3.UID_FUNCTION.ToString();
                        item3Nivel.title = i3.Menu;
                        item3Nivel.type  = "item";
                        item3Nivel.url   = i3.Url;
                        itemSegundoNivel.children.Add(item3Nivel);
                    }
                    itemPrimerNivel.children.Add(itemSegundoNivel);
                }
                menu.Navigation.Add(itemPrimerNivel);
            }

            return(menu);
        }