コード例 #1
0
        public HttpResponseMessage Post(CauseQSE causeQSE /* [FromBody]string value */)
        {
            db.CauseQSEs.Add(causeQSE);
            db.SaveChanges();

            return(Request.CreateResponse <CauseQSE>(HttpStatusCode.OK, causeQSE, Configuration.Formatters.JsonFormatter));
        }
コード例 #2
0
        public IHttpActionResult GetCauseQSE(int id)
        {
            CauseQSE causeQSE = db.CauseQSEs.Find(id);

            if (causeQSE == null)
            {
                return(NotFound());
            }

            return(Ok(causeQSE));
        }
コード例 #3
0
        public IHttpActionResult DeleteCauseQSE(int id)
        {
            CauseQSE causeQSE = db.CauseQSEs.Find(id);

            if (causeQSE == null)
            {
                return(NotFound());
            }

            db.CauseQSEs.Remove(causeQSE);
            db.SaveChanges();

            return(Ok(causeQSE));
        }
コード例 #4
0
        // PUT: api/CauseQSE/5
        //[ResponseType(typeof(void))]
        public HttpResponseMessage PutCauseQSE(int id, CauseQSE causeQSE)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, Configuration.Formatters.JsonFormatter)); // param : ModelState à voir
            }

            if (id != causeQSE.CauseQSEId)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, Configuration.Formatters.JsonFormatter));
            }

            var currentCause = db.CauseQSEs.Find(causeQSE.CauseQSEId);

            db.Entry(currentCause).CurrentValues.SetValues(causeQSE);

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CauseQSEExists(id))
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, Configuration.Formatters.JsonFormatter));
                }
                else
                {
                    throw;
                }
            }

            return(Request.CreateResponse(HttpStatusCode.OK, causeQSE, Configuration.Formatters.JsonFormatter));
        }