Exemplo n.º 1
0
        protected void btnCadastrar_Click(object sender, EventArgs e)
        {
            try
            {
                var IdCategoria = Request.QueryString["Id"];
                var Id          = Convert.ToInt32(IdCategoria);

                var model = _controller.GetById(Id);

                if (model != null)
                {
                    if (String.IsNullOrEmpty(txtNome.Text))
                    {
                        var validaNome = "O campo 'Nome' não pode estar em branco, favor verificar!";
                        ClientScript.RegisterStartupScript(this.GetType(), "script", "alert('" + validaNome + "');", false);

                        return;
                    }

                    model.Nome = txtNome.Text;

                    if (!String.IsNullOrEmpty(txtDescricao.Text))
                    {
                        model.Descricao = txtDescricao.Text;
                    }
                    else
                    {
                        model.Descricao = string.Empty;
                    }

                    if (chkAtivo.Checked)
                    {
                        model.Ativo = 1;
                    }
                    else
                    {
                        model.Ativo = 0;
                    }

                    _controller.Editar(model);
                }
            }
            catch
            {
                throw;
            }

            Response.Redirect("Index.aspx");
        }
Exemplo n.º 2
0
        private void Editar(Categoria categoria)
        {
            if (tbCategoria.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Nome da categoria não pode estar em branco", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                categoria.id   = Convert.ToInt32(tbId.Text);
                categoria.nome = tbCategoria.Text;

                categoriaController.Editar(categoria);

                MessageBox.Show("Categoria alterada com sucesso!");

                Limpar();
                Listar();
            }
        }