public IHttpActionResult PutTermoDeLocacao(int id, TermoDeLocacao termoDeLocacao) //ALTERADO. Pega { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != termoDeLocacao.TermoID) { return(BadRequest()); } db.Entry(termoDeLocacao).State = EntityState.Modified; try { db.SaveChanges(); //ALTERADO } catch (DbUpdateConcurrencyException) { if (!TermoDeLocacaoExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetTermoDeLocacao(int id) //ALTERADO { TermoDeLocacao termoDeLocacao = db.TermoDeLocacaos.Find(id); if (termoDeLocacao == null) { return(NotFound()); } return(Ok(termoDeLocacao)); }
public IHttpActionResult DeleteTermoDeLocacao(int id) //ALTERADO { TermoDeLocacao termoDeLocacao = db.TermoDeLocacaos.Find(id); //ALTERADO if (termoDeLocacao == null) { return(NotFound()); } db.TermoDeLocacaos.Remove(termoDeLocacao); db.SaveChanges(); //ALTERADO return(Ok(termoDeLocacao)); }
public IHttpActionResult PostTermoDeLocacao(TermoDeLocacao termoDeLocacao) //ALTERADO. Insere { if (!ModelState.IsValid) { if (ModelState.Keys.First().ToString() != "termoDeLocacao.Id") //ADICIONADO { return(BadRequest(ModelState)); } } var termo = db.TermoDeLocacaos.FirstOrDefault(x => x.Vigente == true); if (termo != null) { termo.Vigente = false; } db.TermoDeLocacaos.Add(termoDeLocacao); db.SaveChanges(); //ALTERADO return(CreatedAtRoute("DefaultApi", new { id = termoDeLocacao.TermoID }, termoDeLocacao)); }