public Repeticao GetRepeticaoById(int id) { cmd = new SqlCommand("Select * From Repeticao where id = " + id, conn); adapter = new SqlDataAdapter(cmd); dt = new DataTable(); try { conn.Open(); adapter.Fill(dt); foreach (DataRow item in dt.Rows) { repeticao = new Repeticao(); repeticao.Id = Convert.ToInt32(item["id"]); repeticao.Descricao = item["descricao"].ToString(); repeticao.Periodo = item["periodo"].ToString(); repeticao.NumOcorrencias = Convert.ToInt32(item["numOcorrencias"]); repeticao.NumParcelas = Convert.ToInt32(item["numParcelas"]); } } catch (Exception) { throw; } finally { conn.Close(); } return(repeticao); }
public IActionResult Create([FromBody] Repeticao repeticao) { if (repeticao == null) { return(BadRequest()); } _repo.Add(repeticao); return(CreatedAtRoute("GetRepeticao", new { id = repeticao.Id }, repeticao)); }
public void PostRepeticao(Repeticao repeticao) { cmd = new SqlCommand("insert into Repeticao values('" + repeticao.Descricao + "','" + repeticao.Periodo + "'," + repeticao.NumParcelas + "," + repeticao.NumOcorrencias + ")", conn); try { conn.Open(); cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { conn.Close(); } }
public void PutRepeticao(Repeticao repeticao, int id) { cmd = new SqlCommand("Update Repeticao set descricao = '" + repeticao.Descricao + "', periodo = '" + repeticao.Periodo + "', numParcelas = " + repeticao.NumParcelas + ", numOcorrencias =" + repeticao.NumOcorrencias + " where id = " + id, conn); try { conn.Open(); cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { conn.Close(); } }
public IActionResult Update(int id, [FromBody] Repeticao repeticao) { if (repeticao == null || id != repeticao.Id) { return(BadRequest()); } var _repeticao = _repo.Find(id); if (_repeticao == null) { return(NotFound()); } _repeticao.Descricao = repeticao.Descricao; _repeticao.Periodo = repeticao.Periodo; _repeticao.NumOcorrencias = repeticao.NumOcorrencias; _repeticao.NumParcelas = repeticao.NumParcelas; _repo.Update(_repeticao); return(new NoContentResult()); }
public void Update(Repeticao repeticao) { _context.Repeticao.Update(repeticao); _context.SaveChanges(); }
public void Add(Repeticao repeticao) { _context.Repeticao.Add(repeticao); _context.SaveChanges(); }