public List <Model.Categoria> Select() { List <Model.Categoria> lstCategoria = new List <Model.Categoria>(); SqlConnection conexao = new SqlConnection(strCon); string sql = "Select * from Categorias;"; SqlCommand cmd = new SqlCommand(sql, conexao); conexao.Open(); SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); try { while (reader.Read()) { Model.Categoria categoria = new Model.Categoria(); categoria.IdCategoria = Convert.ToInt32(reader[0]); categoria.Descricao = reader["Descricao"].ToString(); categoria.Valor = Convert.ToDecimal(reader["Valor"]); categoria.qtdeVeiculos = Convert.ToInt32(reader["qtdeVeiculos"]); lstCategoria.Add(categoria); } } finally { conexao.Close(); } return(lstCategoria); }
// POST api/categorias public HttpResponseMessage Post(Model.Categoria categoria) { _tareasService.RegistrarCategoria(categoria); var response = Request.CreateResponse(HttpStatusCode.Created, categoria); return(response); }
public Model.Categoria SelectCategoriaById(int id) { Model.Categoria categoria = new Model.Categoria(); SqlConnection conexao = new SqlConnection(strCon); string sql = "Select * from Categorias where idCategoria=@id;"; SqlCommand cmd = new SqlCommand(sql, conexao); cmd.Parameters.AddWithValue("@id", id); conexao.Open(); SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); try { if (reader.Read()) { categoria.IdCategoria = Convert.ToInt32(reader[0]); categoria.Descricao = reader["Descricao"].ToString(); categoria.Valor = Convert.ToDecimal(reader["Valor"]); categoria.qtdeVeiculos = Convert.ToInt32(reader["qtdeVeiculos"]); } } finally { conexao.Close(); } return(categoria); }
protected void btnCadastrar_Click(object sender, EventArgs e) { var model = new Model.Categoria(); try { 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; model.Descricao = txtDescricao.Text; if (!chkAtivo.Checked) { model.Ativo = 0; // Inativo } else { model.Ativo = 1; // Ativo } _controller.Create(model); } catch { throw; } Response.Redirect("Index.aspx"); }
public void EliminarCategoria(int id) { byte idCategoria = (byte)id; Model.Categoria categoria = _categoriaRepository.FindBy(idCategoria); _categoriaRepository.Remove(categoria); _unitOfWork.Commit(); }
public void clean() { editarBtn.Enabled = false; removerBtn.Enabled = false; nomeTb.Text = ""; categoria = null; this.populateGrid(null); }
private Model.Categoria BuildModel(DbDataReader reader) { Model.Categoria categoria = new Model.Categoria(); categoria.ID = reader.ToInt32("CTID"); categoria.Descricao = reader.ToString("CTCATEGORIA"); return(categoria); }
public void ModificarCategoria(Model.Categoria categoria) { Model.Categoria categoriaModificar = _categoriaRepository.FindBy(categoria.Id); categoriaModificar.Nombre = categoria.Nombre; categoriaModificar.Descripcion = categoria.Descripcion; _categoriaRepository.Save(categoriaModificar); _unitOfWork.Commit(); }
// PUT api/categorias/5 public HttpResponseMessage Put(int id, Model.Categoria categoria) { if (id != categoria.Id) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } _tareasService.ModificarCategoria(categoria); return(Request.CreateResponse(HttpStatusCode.OK)); }
private void dataGrid_CellClick(object sender, DataGridViewCellEventArgs e) { editarBtn.Enabled = true; removerBtn.Enabled = true; int rowIndex = e.RowIndex; DataGridViewRow row = dataGrid.Rows[rowIndex]; string id = row.Cells["idColumn"].Value.ToString(); categoria = (Model.Categoria)categoriaDao.getById(int.Parse(id)); }
public void Delete(Model.Veiculo veiculo) { DAL.Veiculo dalVeiculo = new DAL.Veiculo(); BLL.Categoria bllCategoria = new BLL.Categoria(); Model.Categoria categoria = new Model.Categoria(); categoria = bllCategoria.SelectCategoriaById(veiculo.Categoria); categoria.qtdeVeiculos = categoria.qtdeVeiculos - 1; bllCategoria.Update(categoria); dalVeiculo.Delete(veiculo); }
public bool Add(Model.Categoria objeto) { var retorno = context.ListarCategoria().Any(p => p.Descricao == objeto.Descricao); if (!retorno) { context.Add(objeto); return(true); } return(false); }
private void Fill(List <Model.Categoria> list, DataTable dt) { foreach (DataRow dr in dt.Rows) { var c = new Model.Categoria(this) { Id = Convert.ToInt32(dr["id"]), Nome = Convert.ToString(dr["Nome"]), Descricao = dr["Descricao"] == DBNull.Value ? string.Empty : Convert.ToString(dr["Descricao"]) }; list.Add(c); } }
public static void Inserir(Model.Categoria obj) { using (var c = new OracleConnection(Helper.Oracle.CS)) { const String cmd = "INSERT INTO BLOG.CATEGORIA (DESCRICAO_CATEGORIA) VALUES (:DESCRICAO_CATEGORIA)"; using (var k = new OracleCommand(cmd, c)) { k.Parameters.Add(":DESCRICAO_CATEGORIA", obj.Descricao); c.Open(); k.ExecuteNonQuery(); c.Close(); } } }
public static void Alterar(Model.Categoria obj) { using (var c = new OracleConnection(Helper.Oracle.CS)) { const String cmd = "UPDATE BLOG.CATEGORIA SET DESCRICAO_CATEGORIA = :DESCRICAO_CATEGORIA, DATA_EXCLUSAO_CATEGORIA = :DATA_EXCLUSAO_CATEGORIA WHERE CODIGO_CATEGORIA = :CODIGO_CATEGORIA"; using (var k = new OracleCommand(cmd, c)) { k.Parameters.Add(":DESCRICAO_CATEGORIA", obj.Descricao); k.Parameters.Add(":DATA_EXCLUSAO_CATEGORIA", obj.DataExclusao); k.Parameters.Add(":CODIGO_CATEGORIA", obj.Codigo); c.Open(); k.ExecuteNonQuery(); c.Close(); } } }
public void Delete(Model.Categoria categoria) { SqlConnection conexao = new SqlConnection(strCon); string sql = "Delete from Categorias where IdCategoria=@IdCategoria;"; SqlCommand cmd = new SqlCommand(sql, conexao); cmd.Parameters.AddWithValue("@IdCategoria", categoria.IdCategoria); conexao.Open(); try { cmd.ExecuteNonQuery(); } catch { Console.WriteLine("Deu erro na remocao de Categorias..."); } finally { conexao.Close(); } }
public List <Model.Produto> GetList(object obj) { if (obj.GetType().Equals(typeof(string))) { string descricao = (string)obj; return((from Model.Produto x in this.listaprodutos where x.Descricao.Equals(descricao) select x).ToList()); } if (obj.GetType().Equals(typeof(Model.Categoria))) { Model.Categoria categoria = (Model.Categoria)obj; return((from Model.Produto x in this.listaprodutos where x.Categoria.Id.Equals(categoria.Id) select x).ToList()); } return(new List <Model.Produto>()); }
public void Insert(Model.Categoria categoria) { SqlConnection conexao = new SqlConnection(strCon); string sql = "Insert into Categorias values (Descricao, Valor qtdeVeiculos)"; SqlCommand cmd = new SqlCommand(sql, conexao); cmd.Parameters.AddWithValue("@desc", categoria.Descricao); cmd.Parameters.AddWithValue("@valor", categoria.Valor); cmd.Parameters.AddWithValue("@qtde", categoria.qtdeVeiculos); conexao.Open(); try { cmd.ExecuteNonQuery(); } catch { Console.WriteLine("Deu erro na insercao de Categorias"); } finally { conexao.Close(); } }
public void Update(Model.Categoria categoria) { SqlConnection conexao = new SqlConnection(strCon); string sql = "Update Categorias set Descricao=@desc, Valor=@valor, qtdeVeiculos=@qtde where IdCategoria=@IdCategoria"; SqlCommand cmd = new SqlCommand(sql, conexao); cmd.Parameters.AddWithValue("@IdCategoria", categoria.IdCategoria); cmd.Parameters.AddWithValue("@desc", categoria.Descricao); cmd.Parameters.AddWithValue("@valor", categoria.Valor); cmd.Parameters.AddWithValue("@qtde", categoria.qtdeVeiculos); conexao.Open(); try { cmd.ExecuteNonQuery(); } catch { Console.WriteLine("Deu erro na atualizacao de Categorias..."); } finally { conexao.Close(); } }
private void btn_Cadastrar_Click(object sender, EventArgs e) { var categoria = new Model.Categoria { Descricao = txt_Descricao.Text }; var httpClient = new HttpClient(); var URL = $"https://localhost:44360/Categoria/Cadastro"; var novacategoria = JsonConvert.SerializeObject(categoria); StringContent content = new StringContent(novacategoria, Encoding.UTF8, "application/json"); var result = httpClient.PostAsync(URL, content); result.Wait(); var resultado = result.Result.Content.ReadAsStringAsync(); result.Wait(); var resultadoCorpo = JsonConvert.DeserializeObject <Result <List <Usuario> > >(resultado.Result); MessageBox.Show(resultadoCorpo.Mensagem); }
public void Delete(Model.Categoria categoria) { DAL.Categoria dalCategoria = new DAL.Categoria(); dalCategoria.Delete(categoria); }
public void Insert(Model.Categoria categoria) { DAL.Categoria dalCategoria = new DAL.Categoria(); dalCategoria.Insert(categoria); }
public object Selecionar(Model.Categoria categoriaModel) { return(rb.EncapsulatedRead <Model.Categoria>(categoriaModel, "dbo.Categoria_Selecionar", true)); }
private bool ValidaCategoriaOperacao(Model.Categoria objeto) { return(context.ListaOperacaoes().Any(p => p.IdCategoria == objeto.Id)); }
public void Update(Model.Categoria categoria) { DAL.Categoria dalCategoria = new DAL.Categoria(); dalCategoria.Update(categoria); }
public void RegistrarCategoria(Model.Categoria categoria) { _categoriaRepository.Add(categoria); _unitOfWork.Commit(); }
public static void Excluir(Model.Categoria obj) { obj.DataExclusao = DateTime.Now; Alterar(obj); }