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