public void Salvar(TipoCombustivelModel model)
 {
     if (model.Id == 0)
     {
         Adicionar(model);
         return;
     }
     Alterar(model);
 }
        private void Adicionar(TipoCombustivelModel model)
        {
            SqlCommand command = new SqlCommand();

            command.Connection  = Acesso.Connection;
            command.CommandType = CommandType.Text;

            command.CommandText = $"insert into TipoCombustivel (Descricao)values('{model.Descricao}')";
            command.ExecuteNonQuery();
        }
        private void Alterar(TipoCombustivelModel model)
        {
            SqlCommand command = new SqlCommand();

            command.Connection  = Acesso.Connection;
            command.CommandType = CommandType.Text;

            command.CommandText = $"update TipoCombustivel set nome = '{model.Descricao}' where id = {model.Id} ";
            command.ExecuteNonQuery();
        }
Beispiel #4
0
        protected void btnSalvar_Click(object sender, EventArgs e)
        {
            TipoCombustivelModel model = new TipoCombustivelModel();

            model.Descricao = txtDescricao.Text;

            if (txtId.Text != string.Empty)
            {
                model.Id = Convert.ToInt32(txtId.Text);
            }

            var tipoCombustivelBLL = new TipoCombustivelBLL();

            tipoCombustivelBLL.Salvar(model);

            Response.Redirect("./Lista.aspx");
        }
        public TipoCombustivelModel Buscar(int id)
        {
            SqlCommand command = new SqlCommand();

            command.Connection  = Acesso.Connection;
            command.CommandType = CommandType.Text;

            command.CommandText = $"select * from TipoCombustivel where id = {id}";

            SqlDataReader dr = command.ExecuteReader();

            if (dr.Read())
            {
                TipoCombustivelModel model = new TipoCombustivelModel();
                model.Id        = Convert.ToInt32(dr["id"]);
                model.Descricao = dr["Descricao"].ToString();

                return(model);
            }

            return(null);
        }