public ListaGrupoUsuarioTO Listar() { _Contexto = ControladorAcesso.ObterContexto(); ListaGrupoUsuarioTO retorno = new ListaGrupoUsuarioTO(); List <GrupoUsuario> listaGrupoUsuario = _Contexto.GrupoUsuario.ToList(); if (listaGrupoUsuario == null || listaGrupoUsuario.Count == 0) { retorno.Valido = false; retorno.Mensagem = Mensagem.Lista("GrupoUsuario", false); return(retorno); } GrupoUsuarioTO to; foreach (GrupoUsuario entidade in listaGrupoUsuario) { to = new GrupoUsuarioTO(); to.PreencherTO(entidade); retorno.Lista.Add(to); } retorno.Valido = true; retorno.Mensagem = Mensagem.Lista("GrupoUsuario", true); return(retorno); }
public ActionResult Index() { if (Session["MoradorTO"] != null) { return(RedirectToActionPermanent("AccessDenied", "ErrorHandler")); } if (Session["UsuarioTO"] == null) { return(RedirectToActionPermanent("Login", "Home")); } _usuarioTO = (UsuarioTO)Session["UsuarioTO"]; if (!_usuarioTO.Valido) { return(RedirectToActionPermanent("Login", "Home")); } ListaGrupoUsuarioTO listaGrupoUsuario = new ListaGrupoUsuarioTO(); try { listaGrupoUsuario = GrupoUsuarioService.Listar(); var listaGrupoUsuarioesVM = Mapper.Map <List <GrupoUsuarioTO>, List <GrupoUsuarioVM> >(listaGrupoUsuario.Lista); return(View(listaGrupoUsuarioesVM)); } catch (Exception ex) { listaGrupoUsuario.Mensagem = $"Erro ao obter GrupoUsuarioes. Erro: {ex.Message} "; } return(View()); }