// POST: api/MoviesApi public IHttpActionResult Post(MoviePostModel value) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var newItem = new Movie { Id = Movies.Max(x => x.Id) + 1, Title = value.Title, ReleaseYear = value.ReleaseYear }; Movies.Add(newItem); return CreatedAtRoute(WebApiConfig.ApiControllerAndId, new { id = newItem.Id }, newItem); }
// PUT: api/MoviesApi/5 public IHttpActionResult Put(Movie value) { if (!ModelState.IsValid) { return BadRequest(ModelState); } try { var existingItem = Movies.SingleOrDefault(x => x.Id == value.Id); if (existingItem == null) { return NotFound(); } existingItem.Title = value.Title; existingItem.ReleaseYear = value.ReleaseYear; return Ok(existingItem); } catch { return InternalServerError(); } }