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

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

            _ctx.Entry(excercise).State = EntityState.Modified;

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

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

            _ctx.Excercises.Add(newExcercise);
            _ctx.SaveChanges();

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