public IHttpActionResult PutCondominioEntity(int id, CondominioEntity condominioEntity) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != condominioEntity.Id) { return(BadRequest()); } db.Entry(condominioEntity).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CondominioEntityExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetCondominioEntity(int id) { CondominioEntity condominioEntity = db.Condominios.Find(id); if (condominioEntity == null) { return(NotFound()); } return(Ok(condominioEntity)); }
public IHttpActionResult PostCondominioEntity(CondominioEntity condominioEntity) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Condominios.Add(condominioEntity); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = condominioEntity.Id }, condominioEntity)); }
public IHttpActionResult DeleteCondominioEntity(int id) { CondominioEntity condominioEntity = db.Condominios.Find(id); if (condominioEntity == null) { return(NotFound()); } db.Condominios.Remove(condominioEntity); db.SaveChanges(); return(Ok(condominioEntity)); }
public void UpdateCondominioTest() { var controller = new CondominioController(); var Condominio = new CondominioEntity { Id = 1, NomeCondominio = "Update Condominio UnitTest", Administradora = "Update Administrador UniTest", Responsavel = "Update Responsável UnitTest", }; IHttpActionResult actionResult = controller.PutCondominioEntity(Condominio.Id, Condominio); var contentResult = actionResult as NegotiatedContentResult <CondominioEntity>; Assert.IsNull(contentResult); }
public void AddCondominioTest() { var controller = new CondominioController(); var Condominio = new CondominioEntity { NomeCondominio = "Condominio UnitTest", Administradora = "Administrador UniTest", Responsavel = "Responsável UnitTest", }; IHttpActionResult actionResult = controller.PostCondominioEntity(Condominio); var createdResult = actionResult as CreatedAtRouteNegotiatedContentResult <CondominioEntity>; Assert.IsNotNull(createdResult); Assert.AreEqual("DefaultApi", createdResult.RouteName); Assert.IsNotNull(createdResult.RouteValues["id"]); }