Ejemplo n.º 1
0
        public IActionResult CreatePublisher([FromBody] PublisherForCreationDto publisherDto)
        {
            try
            {
                if (publisherDto == null)
                {
                    return(BadRequest());
                }
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }

                var publisherEntity = Mapper.Map <Entities.Publisher>(publisherDto);
                _libraryRepository.AddPublisher(publisherEntity);

                if (!_libraryRepository.Save())
                {
                    return(StatusCode(500, "A problem happened while handling your request."));
                }

                var createdPublisherToReturn = Mapper.Map <PublisherDto>(publisherEntity);
                return(CreatedAtRoute("GetPublisher", new { id = createdPublisherToReturn.Id }, createdPublisherToReturn));
            }
            catch (Exception)
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }
        }
        public IActionResult CreatePublisher([FromBody] PublisherForManipulationDto publisherToAdd)
        {
            var publisherEntity = _mapper.Map <Publisher>(publisherToAdd);

            _repo.AddPublisher(publisherEntity);
            _repo.Save();
            var publisherToReturn = _mapper.Map <PublisherForReturnDto>(publisherEntity);

            return(CreatedAtRoute("GetPublisher", new { id = publisherToReturn.Id }, publisherToReturn));
        }