示例#1
0
        public async Task <BaseResponseMessage> UpdatePublisher(PublisherModel publisher)
        {
            var newPublisher = _mapper.Map <Publisher>(publisher);

            var response = new BaseResponseMessage();

            var publisherToUpdate = await _publisherRepository.GetPublisher(newPublisher.Id);

            if (publisherToUpdate == null)
            {
                response.RawData = $"Publisher with {newPublisher.Id} wasn't found.";
                return(response);
            }

            if (newPublisher.Equals(publisherToUpdate))
            {
                response.RawData = $"Publisher {newPublisher.Name} already existing with similar data.";
                return(response);
            }

            await _publisherRepository.UpdatePublisher(newPublisher);

            response.Id = newPublisher.Id;
            return(response);
        }
        // Szczegóły wydawcy
        public async Task <IActionResult> Details(int id)
        {
            var publisher = await _publisherRepository.GetPublisher(id);

            if (publisher == null)
            {
                return(View("NotFound"));
            }

            return(View(publisher));
        }
示例#3
0
        public ActionResult <Dto.Book> CreateEdition(Dto.EditionRequest request)
        {
            var       edition   = _mapper.Map <Edition>(request);
            var       book      = _bookRepository.GetBook(request.BookId);
            Publisher publisher = null;

            if (book == null)
            {
                return(BadRequest("Book not found"));
            }

            if (request.PublisherName != null)
            {
                string publisherName = request.PublisherName;
                publisher = _publisherRepository.GetPublisher(publisherName);
                if (publisher == null)
                {
                    Publisher newPublisher = new Publisher
                    {
                        Name = request.PublisherName
                    };
                    _publisherRepository.CreatePublisher(newPublisher);
                    if (_publisherRepository.SaveChanges() == false)
                    {
                        return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
                    }
                    publisher = _publisherRepository.GetPublisher(publisherName);
                }
            }

            _repository.CreateEdition(edition, book, publisher);

            if (_repository.SaveChanges() == false)
            {
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }

            return(CreatedAtAction("GetEdition", new { Id = edition.Id }, _mapper.Map <Dto.Edition>(edition)));
        }