Esempio n. 1
0
        // POST api/Avis
        public HttpResponseMessage PostvAvis(vAvis vavis)
        {
            if (ModelState.IsValid)
            {
                db.vAvis.Add(vavis);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, vavis);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = vavis.id }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Esempio n. 2
0
        // PUT api/Avis/5
        public HttpResponseMessage PutvAvis(int id, vAvis vavis)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

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

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }