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

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

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

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

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

            db.RobotParts.Add(robotPart);
            db.SaveChanges();

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