public IHttpActionResult PostPais(Pais pais) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Pais.Add(pais); try { db.SaveChanges(); } catch (DbEntityValidationException db) { foreach (var validationErrors in db.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } return CreatedAtRoute("DefaultApi", new { id = pais.cd_pais }, pais); }
public IHttpActionResult PutPais(int id, Pais pais) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != pais.cd_pais) { return BadRequest(); } db.Entry(pais).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PaisExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }