Ejemplo n.º 1
0
        // PUT api/Cardio/5
        public HttpResponseMessage PutCardio(int id, Cardio cardio)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

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

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }
Ejemplo n.º 2
0
        // POST api/Cardio
        public HttpResponseMessage PostCardio(Cardio cardio)
        {
            if (ModelState.IsValid)
            {
                db.Cardios.Add(cardio);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, cardio);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = cardio.id }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }