public ActionResult Create(DependenteVM Dependente)
        {
            if (ModelState.IsValid)
            {
                var DependenteTO = Mapper.Map <DependenteVM, DependenteTO>(Dependente);

                DependenteService.Criar(DependenteTO);

                Session["Mensagem"] = DependenteTO.Mensagem;
                return(RedirectToAction("Index"));
            }

            return(View());
        }
        public ActionResult Create()
        {
            _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();

            DependenteVM dependente = new DependenteVM();

            if (_moradorTO != null)
            {
                dependente.IdMorador   = _moradorTO.Identificador;
                dependente.NomeMorador = _moradorTO.Nome;
            }

            return(View(dependente));
        }
        private void NomearVariaveis(DependenteVM DependenteVM = null, List <DependenteVM> listaDependenteVM = null)
        {
            var listaMoradorTO = MoradorService.Listar().Lista;

            if (listaDependenteVM != null && listaDependenteVM.Count > 0)
            {
                foreach (var con in listaDependenteVM)
                {
                    con.NomeMorador = listaMoradorTO.FirstOrDefault(x => x.Identificador == con.IdMorador).Nome;
                }
            }

            if (DependenteVM != null)
            {
                DependenteVM.NomeMorador = listaMoradorTO.FirstOrDefault(x => x.Identificador == DependenteVM.IdMorador).Nome;
            }
        }
        public ActionResult Edit(DependenteVM DependenteVM)
        {
            if (ModelState.IsValid)
            {
                var DependenteTO = Mapper.Map <DependenteVM, DependenteTO>(DependenteVM);

                DependenteService.Atualizar(DependenteTO);

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

                DependenteVM = Mapper.Map <DependenteTO, DependenteVM>(DependenteTO);
            }

            return(RedirectToAction("Index"));
        }