コード例 #1
0
        // PUT api/Page/5
        public HttpResponseMessage PutPAGE(int id, PAGE page)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != page.ID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            db.Entry(page).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }
コード例 #2
0
        // POST api/Page
        public HttpResponseMessage PostPAGE(PAGE page)
        {
            if (ModelState.IsValid)
            {
                db.PAGES.Add(page);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, page);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = page.ID }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }