zijiAPIMVC

2021-04-26 15:45

阅读:534

标签:http   pre   mes   post   sap   server   put   res   default   

public class newsApiController : ApiController
    {
        zhoukao0821Entities db = new zhoukao0821Entities();
        // GET: api/newsApi
        public IEnumerable 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 };
            }
            
        }
    }
}

zijiAPIMVC

标签:http   pre   mes   post   sap   server   put   res   default   

原文地址:http://www.cnblogs.com/jin68/p/7881184.html


评论


亲,登录后才可以留言!