Пример #1
0
        // POST api/GLedger
        public HttpResponseMessage PostGLedger(GLedger gledger)
        {
            if (ModelState.IsValid)
            {
                db.GLedgers.Add(gledger);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, gledger);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = gledger.GLedgerID }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Пример #2
0
        // PUT api/GLedger/5
        public HttpResponseMessage PutGLedger(long id, GLedger gledger)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

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

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }