예제 #1
0
        // POST api/ContactLink
        public HttpResponseMessage PostContactLink(ContactLink contactlink)
        {
            if (ModelState.IsValid)
            {
                db.ContactLinks.Add(contactlink);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, contactlink);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = contactlink.ContactLinkId }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
예제 #2
0
        // PUT api/ContactLink/5
        public HttpResponseMessage PutContactLink(Guid id, ContactLink contactlink)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != contactlink.ContactLinkId)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }