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

            if (id != specialItem.SpecialItemID)
            {
                return BadRequest();
            }

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

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

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

            db.SpecialItems.Add(specialItem);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = specialItem.SpecialItemID }, specialItem);
        }