Ejemplo n.º 1
0
        public HttpResponseMessage PostPedometer(Pedometer pedometer)
        {
            if (ModelState.IsValid)
            {
                db.Pedometers.Add(pedometer);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, pedometer);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = pedometer.id }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Ejemplo n.º 2
0
        public HttpResponseMessage PutPedometer(int id, Pedometer pedometer)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != pedometer.id)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
            pedometer.trandate = new DateTime(pedometer.trandate.Year, pedometer.trandate.Month, pedometer.trandate.Day, 0, 0, 0, DateTimeKind.Utc);
            db.Entry(pedometer).State = EntityState.Modified;

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }