public void Atualizar(OcorrenciaTO to)
        {
            _Contexto = ControladorAcesso.ObterContexto();

            if (to.Identificador == 0 || to == null)
            {
                to.Valido   = false;
                to.Mensagem = Mensagem.Atualizacao("Ocorrencia", false);

                return;
            }

            Ocorrencia entidade = _Contexto.Ocorrencia.FirstOrDefault(x => x.Identificador == to.Identificador);

            if (entidade == null)
            {
                to.Valido   = false;
                to.Mensagem = Mensagem.Obter("Ocorrencia", false);

                return;
            }

            to.PreencherEntidade(entidade);

            _Contexto.SaveChanges();

            to.PreencherTO(entidade);
            to.Valido   = true;
            to.Mensagem = Mensagem.Atualizacao("Ocorrencia", true);

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

            ListaOcorrenciaTO retorno = new ListaOcorrenciaTO();

            List <Ocorrencia> listaOcorrencia = _Contexto.Ocorrencia.ToList();

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

                return(retorno);
            }

            OcorrenciaTO to;

            foreach (Ocorrencia entidade in listaOcorrencia)
            {
                to = new OcorrenciaTO();
                to.PreencherTO(entidade);

                retorno.Lista.Add(to);
            }

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

            return(retorno);
        }
Beispiel #3
0
        private void btnSalvarOco_Click(object sender, EventArgs e)
        {
            string erro = String.Empty;

            if (!ValidarCampos(out erro))
            {
                MessageBox.Show(erro, "Atenção");
            }

            OcorrenciaTO ocorrenciaTO = new OcorrenciaTO();

            ocorrenciaTO.IdMorador      = Convert.ToInt32(txtCodMorCadOco.Text);
            ocorrenciaTO.DataOcorrencia = Convert.ToDateTime(txtDataCadOco.Text);
            ocorrenciaTO.Motivo         = txtMotivoCadOco.Text;
            ocorrenciaTO.Descricao      = rtxtDescricaoOco.Text;

            OcorrenciaService.Criar(ocorrenciaTO);

            if (!ocorrenciaTO.Valido)
            {
                MessageBox.Show(ocorrenciaTO.Mensagem, "Atenção");
                return;
            }

            this.Close();
        }
        private void btnSalvarEdicaoOcorrencia_Click(object sender, EventArgs e)
        {
            OcorrenciaTO ocorrenciaTO = new OcorrenciaTO();

            ocorrenciaTO.Motivo        = txtEditarMotivoOcorrencia.Text;
            ocorrenciaTO.Identificador = Convert.ToInt32(lblEditarCodOcorrencia.Text);
            ocorrenciaTO.Descricao     = rtxtEditarDescricaoOcorrencia.Text;

            OcorrenciaService.Atualizar(ocorrenciaTO);

            if (!ocorrenciaTO.Valido)
            {
                MessageBox.Show(ocorrenciaTO.Mensagem);
            }

            this.Close();
        }
        public void Cadastrar(OcorrenciaTO to)
        {
            _Contexto = ControladorAcesso.ObterContexto();

            Ocorrencia entidade = new Ocorrencia();

            to.PreencherEntidade(entidade);

            _Contexto.Ocorrencia.Add(entidade);
            _Contexto.SaveChanges();

            to.PreencherTO(entidade);

            to.Valido   = true;
            to.Mensagem = Mensagem.Cadastro("Ocorrencia");

            return;
        }
Beispiel #6
0
        private void PreencherCampos(int id)
        {
            OcorrenciaTO ocorrenciaTO = new OcorrenciaTO();

            ocorrenciaTO = OcorrenciaService.Obter(id);

            if (!ocorrenciaTO.Valido)
            {
                //Todo: Exibir Mensagem e Fechar Form
                MessageBox.Show(ocorrenciaTO.Mensagem, "Atenção");
                this.Close();
            }

            txtExcluirCodMorOcorrencia.Text     = Convert.ToString(ocorrenciaTO.IdMorador);
            txtExcluirMotivoOcorrencia.Text     = ocorrenciaTO.Motivo;
            rtxtExcluirDescricaoOcorrencia.Text = ocorrenciaTO.Descricao;

            lblExcluirCodOcorrencia.Text = ocorrenciaTO.Identificador.ToString();
        }
        public OcorrenciaTO Obter(int identificador)
        {
            _Contexto = ControladorAcesso.ObterContexto();

            OcorrenciaTO retorno = new OcorrenciaTO();

            Ocorrencia entidade = _Contexto.Ocorrencia.FirstOrDefault(x => x.Identificador == identificador);

            if (entidade == null)
            {
                retorno.Valido   = false;
                retorno.Mensagem = Mensagem.Obter("Ocorrencia", false);

                return(retorno);
            }

            retorno.PreencherTO(entidade);

            retorno.Valido   = true;
            retorno.Mensagem = Mensagem.Obter("Ocorrencia", true);

            return(retorno);
        }
Beispiel #8
0
        public static void Criar(OcorrenciaTO entidadeTO)
        {
            _Crud = CrudService <OcorrenciaCrud> .ObterInstancia();

            _Crud.Cadastrar(entidadeTO);
        }
Beispiel #9
0
        public static void Atualizar(OcorrenciaTO entidadeTO)
        {
            _Crud = CrudService <OcorrenciaCrud> .ObterInstancia();

            _Crud.Atualizar(entidadeTO);
        }
Beispiel #10
0
        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"));
            }

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

                if (!_moradorTO.Valido)
                {
                    return(RedirectToActionPermanent("Login", "Home"));
                }
            }

            OcorrenciaTO OcorrenciaTO = new OcorrenciaTO();

            try
            {
                OcorrenciaTO = OcorrenciaService.Obter(id);

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

                    return(RedirectToActionPermanent("Index"));
                }

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

            return(View());
        }