public async Task<HttpResponseMessage> PutMovie(int id, Movie movie) { try { if (movie.Id != id) { throw new ValidationException("Invalid movie ID."); } if (ModelState.IsValid) { await _session.StoreAsync(movie); await _session.SaveChangesAsync(); } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } } catch (ValidationException ex) { return Request.CreateResponse(HttpStatusCode.NotAcceptable, ex.Message); } return Request.CreateResponse(HttpStatusCode.OK); }
public async Task<HttpResponseMessage> PostMovie(Movie movie) { try { if (ModelState.IsValid) { await _session.StoreAsync(movie); await _session.SaveChangesAsync(); HttpResponseMessage result = Request.CreateResponse(HttpStatusCode.Created, movie); result.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = movie.Id })); return result; } return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } catch (ValidationException ex) { return Request.CreateResponse(HttpStatusCode.NotAcceptable, ex.Message); } }
public void PostMovie(Movie movie) { _session.Store(movie); _session.SaveChanges(); }