zijiAPIMVC
2021-04-26 15:45
标签:http pre mes post sap server put res default public class newsApiController : ApiController // GET: api/newsApi/5 // POST: api/newsApi // PUT: api/newsApi/5 // DELETE: api/newsApi/5 } zijiAPIMVC 标签:http pre mes post sap server put res default 原文地址:http://www.cnblogs.com/jin68/p/7881184.html
{
zhoukao0821Entities db = new zhoukao0821Entities();
// GET: api/newsApi
public IEnumerable
{
return db.newsinfoer;
}
public newsinfo Get(int id)
{
var nid = db.newsinfoer.Where(P => P.nid == id).FirstOrDefault();
return nid;
}
public void Post([FromBody]newsinfo value)
{
db.newsinfoer.Add(value);
db.SaveChanges();
}
public void Put(int id, [FromBody]newsinfo value)
{
var nid = db.newsinfoer.Where(P => P.nid == id).FirstOrDefault();
nid = value;
db.SaveChanges();
}
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 };
}
}
}
}