コード例 #1
0
        // POST api/AppUserContact
        public HttpResponseMessage PostAppUserContact(AppUserContact appusercontact)
        {
            if (ModelState.IsValid)
            {
                db.AppUserContacts.Add(appusercontact);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, appusercontact);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = appusercontact.AppUserContactId }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
コード例 #2
0
        // PUT api/AppUserContact/5
        public HttpResponseMessage PutAppUserContact(Guid id, AppUserContact appusercontact)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != appusercontact.AppUserContactId)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }