Ejemplo n.º 1
0
        protected void CadastrarTarefa_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();


            var NovaTarefa = new Tarefa();

            var tarefaController = new TarefaController();

            bool cadastrado = tarefaController.Cadastrar(NovaTarefa);
        }
Ejemplo n.º 2
0
        protected void btnSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                var _tarefa     = new Tarefa();
                var _controller = new TarefaController();

                if (!String.IsNullOrEmpty(dtDataEntrega.Text))
                {
                    _tarefa.DataEntrega = DateTime.ParseExact(dtDataEntrega.Text, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
                }
                if (!String.IsNullOrEmpty(txtDescricao.Text))
                {
                    _tarefa.Descricao = txtDescricao.Text;
                }
                _tarefa.Entregue = chkEntregue.Checked;
                if (!String.IsNullOrEmpty(txtNota.Text))
                {
                    _tarefa.Nota = Convert.ToByte(txtNota.Text);
                }
                if (!String.IsNullOrEmpty(txtTipo.Text))
                {
                    _tarefa.Tipo = txtTipo.Text;
                }
                if (!String.IsNullOrEmpty(txtTitulo.Text))
                {
                    _tarefa.Titulo = txtTitulo.Text;
                }

                var response = _controller.Cadastrar(_tarefa);

                if (response)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Sucesso", "alert('Tarefa Salva com sucesso');", true);
                    Response.Redirect("~/");
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Erro", "alert('Não foi possível salvar.');", true);
                }
            }
            catch (Exception err)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "Erro", $"alert('erro ao tentar executar: {err.Message}');", true);
            }
        }