Exemplo n.º 1
0
        // PUT api/TravelMode/5
        public HttpResponseMessage PutTravelMode(byte id, TravelMode travelmode)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

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

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }
Exemplo n.º 2
0
        // POST api/TravelMode
        public HttpResponseMessage PostTravelMode(TravelMode travelmode)
        {
            if (ModelState.IsValid)
            {
                db.TravelModes.Add(travelmode);
                db.SaveChanges();

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