Exemple #1
0
        // POST api/Default1
        public HttpResponseMessage PostHOP(HOP hop)
        {
            if (ModelState.IsValid)
            {
                db.Hops.Add(hop);
                db.SaveChanges();

                var response = Request.CreateResponse(HttpStatusCode.Created, hop);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = hop.Id }));
                return response;
            }
            return Request.CreateResponse(HttpStatusCode.BadRequest);
        }
Exemple #2
0
        // PUT api/Default1/5
        public HttpResponseMessage PutHOP(int id, HOP hop)
        {
            if (ModelState.IsValid && id == hop.Id)
            {
                db.Entry(hop).State = EntityState.Modified;

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

                return Request.CreateResponse(HttpStatusCode.OK, hop);
            }
            return Request.CreateResponse(HttpStatusCode.BadRequest);
        }