// GET api/BreakingNewsTypes/5 public BreakingNewsType GetBreakingNewsType(int id) { BreakingNewsType BreakingNewsType = db.BreakingNewsTypes.Single(u => u.ID == id); if (BreakingNewsType == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } return(BreakingNewsType); }
// PUT api/BreakingNewsTypes/5 public HttpResponseMessage PutBreakingNewsType(int id, BreakingNewsType BreakingNewsType) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != BreakingNewsType.ID) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } db.BreakingNewsTypes.Attach(BreakingNewsType); db.ObjectStateManager.ChangeObjectState(BreakingNewsType, EntityState.Modified); try { db.SaveChanges(); Utilities.BreakingNewsTypesLoad(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); /*if (ModelState.IsValid && id == BreakingNewsType.BreakingNewsTypeID) * { * //db.Entry(Playlist).State = EntityState.Modified; * * try * { * db.SaveChanges(); * } * catch (DbUpdateConcurrencyException) * { * return Request.CreateResponse(HttpStatusCode.NotFound); * } * * return Request.CreateResponse(HttpStatusCode.OK); * } * else * { * return Request.CreateResponse(HttpStatusCode.BadRequest); * }*/ }
// POST api/BreakingNewsTypes public HttpResponseMessage PostBreakingNewsType(BreakingNewsType BreakingNewsType) { if (ModelState.IsValid) { db.BreakingNewsTypes.AddObject(BreakingNewsType); db.SaveChanges(); Utilities.BreakingNewsTypesLoad(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, BreakingNewsType); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = BreakingNewsType.ID })); return(response); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }