// POST: odata/TechnicalObjects public IHttpActionResult Post(TechnicalObjects technicalobjects) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.TechnicalObjects.Add(technicalobjects); try { db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } throw new System.Data.Entity.Validation.DbEntityValidationException("Entity Validation Failed - errors follow:\n" + sb.ToString(), ex); } return(Created(technicalobjects)); }
// DELETE: odata/TechnicalObjects(5) public IHttpActionResult Delete([FromODataUri] Int32 key) { TechnicalObjects technicalobjects = db.TechnicalObjects.Find(key); if (technicalobjects == null) { return(NotFound()); } db.TechnicalObjects.Remove(technicalobjects); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TechnicalObjectsExists(key)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult Patch([FromODataUri] Int32 key, Delta <TechnicalObjects> patch) { Validate(patch.GetEntity()); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } TechnicalObjects technicalobjects = db.TechnicalObjects.Find(key); if (technicalobjects == null) { return(NotFound()); } patch.Patch(technicalobjects); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TechnicalObjectsExists(key)) { return(NotFound()); } else { throw; } } return(Updated(technicalobjects)); }