예제 #1
0
        [HttpPost] //Define this method as a POST
        public async Task<IHttpActionResult> RecordNewPlay(Play play)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Plays.Add(play);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = play.Id }, new Models.DTO.Play(play));
        }
예제 #2
0
        [HttpPut] //Define this method as a PUT
        public async Task<IHttpActionResult> EditPlay(int id, Play play)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            if (id != play.Id)
            {
                return BadRequest();
            }

            db.Entry(play).State = System.Data.Entity.EntityState.Modified;
            await db.SaveChangesAsync();

            return StatusCode(HttpStatusCode.NoContent);
        }