예제 #1
0
        //[Display(Name = "Usuario")]
        //public string UserName { get { return Usuario.UserName; } }
        //public Usuario Usuario { get; set; }

        //[Display(Name = "Empresas")]
        //public string EmpresasRol
        //{
        //    get
        //    {
        //        StringBuilder sb = new StringBuilder();
        //        // Si es para todos
        //        if (this.GrupoEmpresarial == null && this.Compania == null && this.Division == null && this.Sucursal == null)
        //            return "Todos los Grupos y Empresas";

        //        if (this.GrupoEmpresarial != null)
        //            sb.Append("Grupo : " + this.GrupoEmpresarial.Descripcion);

        //        if (this.Compania != null)
        //        {
        //            sb.Append("- Empresa : " + this.Compania.Descripcion);
        //        }

        //        if (this.Division != null)
        //        {
        //            sb.Append("- División : " + this.Division.Descripcion);
        //        }

        //        if (this.Sucursal != null)
        //        {
        //            sb.Append("- Sucursal : " + this.Sucursal.Descripcion);
        //        }

        //        return sb.ToString();

        //    }
        //}


        //[Required]
        //[Display(Name="Nombre Rol")]
        //public string RolNombre { get { return this.Rol.RoleName; } }

        //public GrupoEmpresarial GrupoEmpresarial { get; set; }

        //public Compania Compania { get; set; }

        //public Division Division { get; set; }

        //public Sucursal Sucursal { get; set; }

        //public Rol Rol { get; set; }



        #region Methods

        public static string GetEmpresasRol(RolEmpresa rolEmpresa)
        {
            StringBuilder sb = new StringBuilder();


            return(sb.ToString());
        }
        public RolEmpresaViewModel(RolEmpresa rolempresa)
        {
            this.Id = rolempresa.Id;

            this.Rol = rolempresa.Rol;

            this.Usuario = rolempresa.Usuario;
        }
예제 #3
0
        /// <summary>
        /// Obtiene los Modulos Permitidos de un Perfil
        /// </summary>
        /// <param name="RolesEmpresa"></param>
        /// <returns></returns>
        public List <Modulo> GetModulosUser(ICollection <RolEmpresa> RolesEmpresa, ICollection <Modulo> Modulos)
        {
            RolEmpresa re = null;

            //if (perfilUsuario != null)
            re = RolesEmpresa.First();

            if (re == null && RolesEmpresa.Count() > 0)
            {
                re = re = RolesEmpresa.First();
            }
            List <Modulo> listResult = new List <Modulo>();

            try
            {
                foreach (var ob2 in re.Rol.ModulosPermiso)
                {
                    Modulo modulo2 = Modulos.Where(f => f.Id == 111 && f.Visible).FirstOrDefault();
                    Modulo modulo  = Modulos.Where(f => f.Id == ob2.Modulo_Id && f.Visible).FirstOrDefault();
                    if (modulo != null)
                    {
                        if (modulo.Id == 111)
                        {
                        }

                        var itemAdd = listResult.FirstOrDefault(f => f.Id == modulo.Id);
                        if (itemAdd == null)
                        {
                            listResult.Add(modulo);
                        }


                        var parents = GetParentsList(modulo, Modulos);

                        foreach (var parent in parents)
                        {
                            var item = listResult.FirstOrDefault(f => f.Id == parent.Id);
                            if (item == null)
                            {
                                listResult.Add(parent);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            return(listResult);
        }
예제 #4
0
        /// <summary>
        /// Determina si el usuario tiene permiso sobre el Modulo y la Accion
        /// </summary>
        /// <param name="modulo"></param>
        /// <param name="accion"></param>
        /// <returns></returns>
        public bool Has_Perm(string modulo, string accion, string permiso)
        {
            //Valido si no existe dos Modulos iguales con diferente accion.
            // var query = this.RolesEmpresa.Select(p=>p.Rol.ModulosPermiso.Select(p.));

            //  return this.RolesEmpresa.Any(p => p.Rol.ModulosPermiso.Select(o => o.Modulo.URL.ToLower() == modulo.ToLower() + "/" + accion.ToLower() && o.Accion == permiso).FirstOrDefault());
            RolEmpresa    re       = null;
            List <string> listPerm = new List <string>();

            if (permiso.Contains(','))
            {
                foreach (var per in permiso.Split(',').ToList())
                {
                    listPerm.Add(per);
                }
            }
            else
            {
                listPerm.Add(permiso);
            }

            re = RolesEmpresa.First();

            if (re == null && RolesEmpresa.Count() > 0)
            {
                re = re = RolesEmpresa.First();
            }
            foreach (var ob2 in re.Rol.ModulosPermiso)
            {
                foreach (var per in listPerm)
                {
                    if (ob2.Modulo.URL.ToUpper().StartsWith(modulo.ToUpper()) && (permiso == string.Empty ? true : ob2.Accion == per))
                    {
                        return(true);
                    }
                }
            }
            //foreach (var ob in this.RolesEmpresa.Select(o => o.Rol.ModulosPermiso))
            //{
            //    foreach (var ob2 in ob.ToList())
            //    {
            //        if (ob2.Modulo.URL.ToUpper().StartsWith(modulo.ToUpper()) && (permiso == string.Empty ?  true : ob2.Accion == permiso))
            //            return true;
            //    }
            //}
            return(false);
        }