public ActionResult Roles(int?Id) { if (User == null || User.GetType().ToString() == "System.Security.Principal.GenericPrincipal") { return(RedirectToAction("Index", "Home")); } ModelState.Clear(); ViewBag.Menu = ClasesVarias.GetMenuUsuario(); ViewBag.Title = Resources.RolesResource.RolesPageTitle; ViewBag.PageHeader = Resources.RolesResource.RolesHeaderPage; RolesViewModel model = new RolesViewModel(); model.Roles = ClasesVarias.GetNivelesUsuario(); model.showModulos = false; if (Id != null) { model.RolID = (int)Id; model.showModulos = true; using (SeguricelEntities db = new SeguricelEntities()) { model.Modulos = (from d in db.Modulo select new RolViewModel { Asignado = (d.Modulo_TipoUsuario.Where(x => x.IdTipoUsuario == model.RolID).Count() > 0), FechaAsignacion = (DateTime)d.Modulo_TipoUsuario.Where(x => x.IdTipoUsuario == (int)Id).FirstOrDefault().FechaAsignacion, IdModulo = d.IdModulo, IdTipoUsuario = (int)Id, Modulo = d.Nombre, ModuloPadre = (d.Modulo2 != null ? d.Modulo2.Nombre : string.Empty) }).ToList(); } } else { model.showModulos = false; model.Modulos = new List <RolViewModel>(); } return(View(model)); }