Exemplo n.º 1
0
        // PUT api/UserInfo/5
        public HttpResponseMessage Putuserinfo(long id, userinfo userinfo)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

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

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }
Exemplo n.º 2
0
        // POST api/UserInfo
        public HttpResponseMessage Postuserinfo(userinfo userinfo)
        {
            if (ModelState.IsValid)
            {
                db.userinfo.Add(userinfo);
                db.SaveChanges();

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