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

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

            db.Entry(results).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/Results
        public HttpResponseMessage Postresults(results results)
        {
            if (ModelState.IsValid)
            {
                db.results.Add(results);
                db.SaveChanges();

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