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"));
            }

            ListaMoradorTO listaMorador = new ListaMoradorTO();

            try
            {
                listaMorador = MoradorService.Listar();
                var listaMoradoresVM = Mapper.Map <List <MoradorTO>, List <MoradorVM> >(listaMorador.Lista);

                return(View(listaMoradoresVM));
            }
            catch (Exception ex)
            {
                listaMorador.Mensagem = $"Erro ao obter moradores. Erro: {ex.Message} ";
            }

            return(View());
        }
        public ListaMoradorTO Listar()
        {
            _Contexto = ControladorAcesso.ObterContexto();

            ListaMoradorTO retorno = new ListaMoradorTO();

            List <Morador> listaMorador = _Contexto.Morador.ToList();

            if (listaMorador == null || listaMorador.Count == 0)
            {
                retorno.Valido   = false;
                retorno.Mensagem = Mensagem.Lista("Morador", false);

                return(retorno);
            }

            MoradorTO to;

            foreach (Morador entidade in listaMorador)
            {
                to = new MoradorTO();
                to.PreencherTO(entidade);

                retorno.Lista.Add(to);
            }

            retorno.Valido   = true;
            retorno.Mensagem = Mensagem.Lista("Morador", true);

            return(retorno);
        }
Exemple #3
0
        public static MoradorTO LoginMorador(string cpf)
        {
            _Crud = CrudService <MoradorCrud> .ObterInstancia();

            MoradorTO retorno = new MoradorTO();

            try
            {
                ListaMoradorTO listaMoradorTO = new ListaMoradorTO();
                listaMoradorTO = _Crud.Listar();

                retorno = listaMoradorTO.Lista.FirstOrDefault(x => x.CPF == cpf);

                if (retorno == null)
                {
                    retorno          = new MoradorTO();
                    retorno.Valido   = false;
                    retorno.Mensagem = "Não há moradores cadastrados na base de dados";

                    return(retorno);
                }

                retorno.Mensagem = "Morador obtido com sucesso.";
                retorno.Valido   = true;
            }
            catch (Exception ex)
            {
                retorno.Valido   = false;
                retorno.Mensagem = string.Format("Erro: {0}", ex.Message);
            }

            return(retorno);
        }
Exemple #4
0
        public static ListaMoradorTO PesquisarPorNome(string nomeMorador)
        {
            _Crud = CrudService <MoradorCrud> .ObterInstancia();

            ListaMoradorTO retorno = new ListaMoradorTO();

            try
            {
                retorno = _Crud.Listar();

                if (retorno.Valido)
                {
                    retorno.Lista = retorno.Lista.Where(x => x.Nome.Contains(nomeMorador)).ToList();
                }
            }
            catch (Exception ex)
            {
                retorno.Valido   = false;
                retorno.Mensagem = string.Format("Erro: {0}", ex.Message);
            }

            return(retorno);
        }
        private void CarregarDados()
        {
            ListaMoradorTO listaMoradoresTO = new ListaMoradorTO();

            listaMoradoresTO = MoradorService.Listar();

            dgMoradores.DataSource = listaMoradoresTO.Lista;
            dgMoradores.Columns["Identificador"].Visible = false;
            dgMoradores.Columns["Valido"].Visible        = false;
            dgMoradores.Columns["Mensagem"].Visible      = false;
            dgMoradores.ReadOnly = true;

            ListaContratoTO listaContratosTO = new ListaContratoTO();

            listaContratosTO = ContratoService.Listar();

            dgContratos.DataSource = listaContratosTO.Lista;
            dgContratos.Columns["Identificador"].Visible = false;
            dgContratos.Columns["Valido"].Visible        = false;
            dgContratos.Columns["Mensagem"].Visible      = false;
            dgContratos.ReadOnly = true;

            ListaDependenteTO listaDependentesTO = new ListaDependenteTO();

            listaDependentesTO = DependenteService.Listar();

            dgDependentes.DataSource = listaDependentesTO.Lista;
            dgDependentes.Columns["Identificador"].Visible = false;
            dgDependentes.Columns["Valido"].Visible        = false;
            dgDependentes.Columns["Mensagem"].Visible      = false;
            dgDependentes.ReadOnly = true;

            ListaEstacionamentoTO listaEstacionamentosTO = new ListaEstacionamentoTO();

            listaEstacionamentosTO = EstacionamentoService.Listar();

            ListaOcorrenciaTO listaOcorrenciasTO = new ListaOcorrenciaTO();

            listaOcorrenciasTO = OcorrenciaService.Listar();

            dgAdmOcorrencias.DataSource = listaOcorrenciasTO.Lista;
            dgAdmOcorrencias.Columns["Identificador"].Visible = false;
            dgAdmOcorrencias.Columns["Valido"].Visible        = false;
            dgAdmOcorrencias.Columns["Mensagem"].Visible      = false;
            dgAdmOcorrencias.ReadOnly = true;

            ListaReservaTO listaReservasTO = new ListaReservaTO();

            listaReservasTO = ReservaService.Listar();

            dgReservas.DataSource = listaReservasTO.Lista;
            dgReservas.Columns["Identificador"].Visible = false;
            dgReservas.Columns["Valido"].Visible        = false;
            dgReservas.Columns["Mensagem"].Visible      = false;
            dgReservas.ReadOnly = true;


            ListaAdvertenciaTO listaAdvertenciasTO = new ListaAdvertenciaTO();

            listaAdvertenciasTO = AdvertenciaService.Listar();
        }