Ejemplo n.º 1
0
        // PUT api/Subjects/5
        public HttpResponseMessage Putsubjects(int id, subjects subjects)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

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

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }
Ejemplo n.º 2
0
        // POST api/Subjects
        public HttpResponseMessage Postsubjects(subjects subjects)
        {
            if (ModelState.IsValid)
            {
                db.subjects.Add(subjects);
                db.SaveChanges();

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