Exemplo n.º 1
0
        // POST api/Shape
        public HttpResponseMessage PostShape(Shape shape)
        {
            if (ModelState.IsValid)
            {
                db.shapes.Add(shape);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, shape);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = shape.shape_id }));
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
Exemplo n.º 2
0
        // PUT api/Shape/5
        public HttpResponseMessage PutShape(string id, Shape shape)
        {
            if (ModelState.IsValid && id == shape.shape_id)
            {
                db.Entry(shape).State = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return Request.CreateResponse(HttpStatusCode.NotFound);
                }

                return Request.CreateResponse(HttpStatusCode.OK);
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }