public async Task <IHttpActionResult> PutTermoLocacao(int id, TermoLocacao termoLocacao) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != termoLocacao.Id) { return(BadRequest()); } db.Entry(termoLocacao).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TermoLocacaoExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void InativarTermo(TermoLocacao termo) { using (SqlConnection connection = new SqlConnection(connectionString)) using (SqlCommand command = new SqlCommand("", connection)) { command.CommandText = "UPDATE TermoLocacoes SET Ativo = false WHERE Ativo = true"; command.ExecuteNonQuery(); } }
public async Task <IHttpActionResult> GetTermoLocacao(int id) { TermoLocacao termoLocacao = await db.termoLocacoes.FindAsync(id); if (termoLocacao == null) { return(NotFound()); } return(Ok(termoLocacao)); }
public async Task <IHttpActionResult> DeleteTermoLocacao(int id) { TermoLocacao termoLocacao = await db.termoLocacoes.FindAsync(id); if (termoLocacao == null) { return(NotFound()); } db.termoLocacoes.Remove(termoLocacao); await db.SaveChangesAsync(); return(Ok(termoLocacao)); }
public async Task <IHttpActionResult> PostTermoLocacao(TermoLocacao termoLocacao) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } validaTextVigente(termoLocacao); db.termosLocacoes.Add(termoLocacao); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = termoLocacao.Id }, termoLocacao)); }
private void validaTextVigente(TermoLocacao termoLocacao) { foreach (var item in db.termosLocacoes) { if (item.Descricao != termoLocacao.Descricao) { db.termosLocacoes.Find(item.Id).Ativo = false; if (item.Id == termoLocacao.Id) { db.termosLocacoes.Add(termoLocacao); } } } }
public async Task <IHttpActionResult> PostTermoLocacao(TermoLocacao termoLocacao) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var termo = db.termoLocacoes.FirstOrDefault(x => x.Ativo == true); if (termo != null) { termo.Ativo = false; } db.termoLocacoes.Add(termoLocacao); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = termoLocacao.Id }, termoLocacao)); }