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

            if (id != hcmember.HcMemberId)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }
コード例 #2
0
        // POST api/HcMember
        public HttpResponseMessage PostHcMember(HcMember hcmember)
        {
            if (ModelState.IsValid)
            {
                db.HcMembers.Add(hcmember);
                db.SaveChanges();

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