Exemplo n.º 1
0
        // PUT api/Normes/5
        public HttpResponseMessage PutNORME(int id, NORME norme)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

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

            db.Entry(norme).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/Normes
        public HttpResponseMessage PostNORME(NORME norme)
        {
            if (ModelState.IsValid)
            {
                db.NORMEs.Add(norme);
                db.SaveChanges();

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