Esempio n. 1
0
        // POST api/SubItems
        public HttpResponseMessage PostSubbItem(SubbItem subbitem)
        {
            if (ModelState.IsValid)
            {
                db.SubItems.Add(subbitem);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, subbitem);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = subbitem.ID }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Esempio n. 2
0
        // PUT api/SubItems/5
        public HttpResponseMessage PutSubbItem(int id, SubbItem subbitem)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

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

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }