コード例 #1
0
        public IHttpActionResult PutWhatDoItem(int id, WhatDoItem whatDoItem)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != whatDoItem.Id)
            {
                return BadRequest();
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WhatDoItemExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
コード例 #2
0
        public IHttpActionResult PostWhatDoItem(WhatDoItem whatDoItem)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.WhatDoItems.Add(whatDoItem);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = whatDoItem.Id }, whatDoItem);
        }