コード例 #1
0
        public HttpResponseMessage PostShow( Show show )
        {
            if (ModelState.IsValid)
            {
                db.Shows.Add(show);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, show);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = show.ShowId }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
コード例 #2
0
        public HttpResponseMessage PutShow(int id, Show show)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

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

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }