public class newsApiController : ApiController
{ zhoukao0821Entities db = new zhoukao0821Entities(); // GET: api/newsApi public IEnumerable<newsinfo> Get() { return db.newsinfoer; } // GET: api/newsApi/5 public newsinfo Get(int id) { var nid = db.newsinfoer.Where(P => P.nid == id).FirstOrDefault(); return nid; } // POST: api/newsApi public void Post([FromBody]newsinfo value) { db.newsinfoer.Add(value); db.SaveChanges(); } // PUT: api/newsApi/5 public void Put(int id, [FromBody]newsinfo value) { var nid = db.newsinfoer.Where(P => P.nid == id).FirstOrDefault(); nid = value; db.SaveChanges(); } // DELETE: api/newsApi/5 public HttpResponseMessage Delete(int id) { var nid = db.newsinfoer.Where(P => P.nid == id).FirstOrDefault(); try { if (nid != null) { db.newsinfoer.Remove(nid); db.SaveChanges(); return new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }; } else { return new HttpResponseMessage() { StatusCode = HttpStatusCode.NoContent }; } } catch { return new HttpResponseMessage() { StatusCode = HttpStatusCode.InternalServerError }; } } }}