Example #1
0
        // POST api/Blocks
        public HttpResponseMessage Post(Block block)
        {
            if (ModelState.IsValid)
            {
                db.Blocks.Add(block);
                db.SaveChanges();

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

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

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