예제 #1
0
        // POST api/Flowers
        public HttpResponseMessage PostFlower(Flower flower)
        {
            if (ModelState.IsValid)
            {
                db.Flowers.Add(flower);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, flower);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = flower.Id }));
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
예제 #2
0
        // PUT api/Flowers/5
        public HttpResponseMessage PutFlower(int id, Flower flower)
        {
            if (ModelState.IsValid && id == flower.Id)
            {
                db.Entry(flower).State = EntityState.Modified;

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

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