示例#1
0
        // PUT api/Equation/5
        public HttpResponseMessage PutEquation(int id, Equation equation)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

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

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }
示例#2
0
        // POST api/Equation
        public HttpResponseMessage PostEquation(Equation equation)
        {
            if (ModelState.IsValid)
            {
                db.Equations.Add(equation);
                db.SaveChanges();

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