예제 #1
0
        // PUT api/Jeux/5
        public HttpResponseMessage PutJEU(int id, JEU jeu)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

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

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

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

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
예제 #2
0
        // GET api/Jeux/5
        public JEU GetJEU(int id)
        {
            JEU jeu = db.JEUs.Find(id);

            if (jeu == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(jeu);
        }
예제 #3
0
        // POST api/Jeux
        public HttpResponseMessage PostJEU(JEU jeu)
        {
            if (ModelState.IsValid)
            {
                db.JEUs.Add(jeu);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, jeu);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = jeu.ID_JEU }));
                return(response);
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
예제 #4
0
        public JEU GetUTILISATEURbyName(string name)
        {
            JEU jeu = new JEU();

            var users = GetJEUs();

            foreach (var i in users)
            {
                if (i.NOM_JEU == name)
                {
                    jeu = i;
                }
            }
            if (jeu == null || jeu.NOM_JEU == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(jeu);
        }
예제 #5
0
        // DELETE api/Jeux/5
        public HttpResponseMessage DeleteJEU(int id)
        {
            JEU jeu = db.JEUs.Find(id);

            if (jeu == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            db.JEUs.Remove(jeu);

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

            return(Request.CreateResponse(HttpStatusCode.OK, jeu));
        }