Ejemplo n.º 1
0
        // POST api/FormList
        public HttpResponseMessage PostFormList(FormList formlist)
        {
            if (ModelState.IsValid)
            {
                db.FormLists.Add(formlist);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, formlist);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = formlist.FormID }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Ejemplo n.º 2
0
        // PUT api/FormList/5
        public HttpResponseMessage PutFormList(long id, FormList formlist)
        {
            formlist.Module = null;
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

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

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }