示例#1
0
        public HttpResponseMessage Post(GenreDTO genre)
        {
            HttpResponseMessage result;

            if (genre == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            try
            {
                var mapper = configToEntity.CreateMapper();
                var g      = mapper.Map <GenreDTO, Genre>(genre);

                var updatedItem = _genreRepo.AddOrUpdate(g);
                _genreRepo.SaveChanges();
                result = Request.CreateResponse(HttpStatusCode.Created, config.CreateMapper().Map <Genre, GenreDTO>(updatedItem));
            }
            catch (Exception ex)
            {
                result = Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, ex);
            }
            return(result);
        }