public ActionResult Details(int id)
        {
            _usuarioTO = (UsuarioTO)Session["UsuarioTO"];
            _moradorTO = (MoradorTO)Session["MoradorTO"];

            if (_usuarioTO != null)
            {
                _usuarioTO = (UsuarioTO)Session["UsuarioTO"];
                if (!_usuarioTO.Valido)
                {
                    return(RedirectToActionPermanent("Login", "Home"));
                }
            }
            else if (_moradorTO != null)
            {
                _moradorTO = (MoradorTO)Session["MoradorTO"];

                if (_moradorTO != null)
                {
                    _moradorTO = (MoradorTO)Session["MoradorTO"];
                    if (!_moradorTO.Valido)
                    {
                        return(RedirectToActionPermanent("Login", "Home"));
                    }
                }
            }
            else
            {
                return(RedirectToActionPermanent("Login", "Home"));
            }

            DependenteTO DependenteTO = new DependenteTO();

            try
            {
                DependenteTO = DependenteService.Obter(id);

                if (!DependenteTO.Valido)
                {
                    Session["Mensagem"] = DependenteTO.Mensagem;

                    return(RedirectToActionPermanent("Index"));
                }

                var DependenteVM = Mapper.Map <DependenteTO, DependenteVM>(DependenteTO);
                NomearVariaveis(DependenteVM, null);
                return(View(DependenteVM));
            }
            catch (Exception ex)
            {
                DependenteTO.Mensagem = $"Erro ao obter Dependente. Erro: {ex.Message}";
            }

            return(View());
        }
        public ActionResult Edit(int id)
        {
            _usuarioTO = (UsuarioTO)Session["UsuarioTO"];
            _moradorTO = (MoradorTO)Session["MoradorTO"];

            if (_usuarioTO != null)
            {
                _usuarioTO = (UsuarioTO)Session["UsuarioTO"];
                if (!_usuarioTO.Valido)
                {
                    return(RedirectToActionPermanent("Login", "Home"));
                }
                else if (_usuarioTO.IdGrupo == 3)
                {
                    return(RedirectToActionPermanent("Index"));
                }
            }
            else if (_moradorTO != null)
            {
                _moradorTO = (MoradorTO)Session["MoradorTO"];

                if (_moradorTO != null)
                {
                    _moradorTO = (MoradorTO)Session["MoradorTO"];
                    if (!_moradorTO.Valido)
                    {
                        return(RedirectToActionPermanent("Login", "Home"));
                    }
                }
            }
            else
            {
                return(RedirectToActionPermanent("Login", "Home"));
            }

            ViewBag.Morador = ListarMoradores();
            if (ModelState.IsValid)
            {
                var DependenteTO = DependenteService.Obter(id);

                if (!DependenteTO.Valido)
                {
                    Session["Mensagem"] = DependenteTO.Mensagem;
                    return(RedirectToAction("Index"));
                }

                var DependenteVM = Mapper.Map <DependenteTO, DependenteVM>(DependenteTO);
                NomearVariaveis(DependenteVM, null);
                return(View(DependenteVM));
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Delete(int id)
        {
            _usuarioTO = (UsuarioTO)Session["UsuarioTO"];
            _moradorTO = (MoradorTO)Session["MoradorTO"];

            if (_usuarioTO != null)
            {
                _usuarioTO = (UsuarioTO)Session["UsuarioTO"];
                if (!_usuarioTO.Valido)
                {
                    return(RedirectToActionPermanent("Login", "Home"));
                }
                else if (_usuarioTO.IdGrupo == 3)
                {
                    return(RedirectToActionPermanent("Index"));
                }
            }
            else if (_moradorTO != null)
            {
                _moradorTO = (MoradorTO)Session["MoradorTO"];

                if (_moradorTO != null)
                {
                    _moradorTO = (MoradorTO)Session["MoradorTO"];
                    if (!_moradorTO.Valido)
                    {
                        return(RedirectToActionPermanent("Login", "Home"));
                    }
                }
            }
            else
            {
                return(RedirectToActionPermanent("Login", "Home"));
            }

            if (id > 0)
            {
                var DependenteTO = DependenteService.Obter(id);
                var DependenteVM = Mapper.Map <DependenteTO, DependenteVM>(DependenteTO);
                NomearVariaveis(DependenteVM, null);
                return(View(DependenteVM));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
        private void PreencherCampos(int id)
        {
            DependenteTO dependenteTO = new DependenteTO();

            dependenteTO = DependenteService.Obter(id);

            if (!dependenteTO.Valido)
            {
                MessageBox.Show(dependenteTO.Mensagem, "Atenção");
                this.Close();
            }

            txtEditarNomeDep.Text                = dependenteTO.Nome;
            txtEditarRgDep.Text                  = dependenteTO.RG;
            txtEditarTelefoneDep.Text            = dependenteTO.Telefone;
            cboEditarGrauParentesco.SelectedItem = dependenteTO.GrauParentesco;
            txtEditarMoradorResp.Text            = Convert.ToString(dependenteTO.IdMorador);
            lblEditarCodigoDep.Text              = dependenteTO.Identificador.ToString();
        }
Пример #5
0
        private void PreencherCampos(int id)
        {
            DependenteTO dependenteTO = new DependenteTO();

            dependenteTO = DependenteService.Obter(id);

            if (!dependenteTO.Valido)
            {
                //Todo: Exibir Mensagem e Fechar Form
                MessageBox.Show(dependenteTO.Mensagem);
                this.Close();
            }

            txtExcluirNomeDep.Text     = dependenteTO.Nome;
            txtExcluirRgDep.Text       = dependenteTO.RG;
            txtExcluirTelefoneDep.Text = dependenteTO.Telefone;
            txtExcluirGrauParent.Text  = dependenteTO.GrauParentesco;
            txtExcluirMoradorResp.Text = Convert.ToString(dependenteTO.IdMorador);
            lblExcluirCodigoDep.Text   = dependenteTO.Identificador.ToString();
        }