예제 #1
0
        // POST api/Bills
        public HttpResponseMessage Post(Bill bill)
        {
            if (ModelState.IsValid)
            {
                db.Bills.Add(bill);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, bill);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = bill.id }));
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
예제 #2
0
        // PUT api/Bills/5
        public HttpResponseMessage Put(int id, Bill bill)
        {
            if (ModelState.IsValid && id == bill.id)
            {
                db.Bills.Attach(bill);
                db.Entry(bill).State = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return Request.CreateResponse(HttpStatusCode.NotFound);
                }

                return Request.CreateResponse(HttpStatusCode.OK);
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }