/// <summary> /// Creates a Movie in the Database /// </summary> /// <param name="movie"></param> /// <returns></returns> public HttpResponseMessage Post(MovieDto movieDto) { try { var movie = new MovieConverter().Convert(movieDto); facade.GetMovieRepository().Add(movie); var response = Request.CreateResponse<MovieDto>(HttpStatusCode.Created, movieDto); var uri = Url.Link("GetMovieById", new { movie.Id }); response.Headers.Location = new Uri(uri); return response; } catch (Exception) { var response = new HttpResponseMessage(HttpStatusCode.Conflict) { Content = new StringContent("Could not add a Movie to the database") }; throw new HttpResponseException(response); } }
/// <summary> /// Updates a Movie in Database /// </summary> /// <param name="movie"></param> /// <returns></returns> public HttpResponseMessage Put(MovieDto movieDto) { try { Movie movie = new MovieConverter().Convert(movieDto); facade.GetMovieRepository().Edit(movie); var response = Request.CreateResponse<MovieDto>(HttpStatusCode.OK, movieDto); var uri = Url.Link("GetMovieById", new { movie.Id }); response.Headers.Location = new Uri(uri); return response; } catch (Exception) { var response = new HttpResponseMessage(HttpStatusCode.Conflict) { Content = new StringContent("No matching customer") }; throw new HttpResponseException(response); } }