Ejemplo n.º 1
0
        /// <summary>
        /// Insert a new movie
        ///
        /// Task: 4) Insert new movie
        /// </summary>
        /// <param name="movieDto">Movie data transaction object</param>
        /// <returns>Insert response in http format.</returns>
        public Dto.MovieDto Post(Dto.MovieDto movieDto)
        {
            var movieData = Mapper.Map <Dto.MovieDto, MoviesLibrary.MovieData>(movieDto);

            movieDto.ID = this.dataProvider.CreateMovie(movieData);

            return(movieDto);;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Update a movie
 ///
 /// Task: 5) Update existing movie.
 /// </summary>
 /// <param name="id">Movie ID</param>
 /// <param name="movieDto">Movie data transaction object</param>
 public void Put(int id, [FromBody] Dto.MovieDto movieDto)
 {
     try
     {
         this.service.Put(id, movieDto);
     }
     catch (Exception ex)
     {
         Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
         throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.InternalServerError, "Unexpected exception occured."));
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Insert a new movie
        ///
        /// Task: 4) Insert new movie
        /// </summary>
        /// <param name="movieDto">Movie data transaction object</param>
        /// <returns>Insert response in http format.</returns>
        public HttpResponseMessage Post([FromBody] Dto.MovieDto movieDto)
        {
            try
            {
                movieDto = this.service.Post(movieDto);

                var response = Request.CreateResponse <Dto.MovieDto>(HttpStatusCode.Created, movieDto);

                string uri = Url.Link("DefaultApi", new { id = movieDto.ID });
                response.Headers.Location = new Uri(uri);
                return(response);
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.InternalServerError, "Unexpected exception occured."));
            }
        }