Ejemplo n.º 1
0
        public IActionResult Post([FromRoute] int userId, [FromBody] PostBookHttpRequest request)
        {
            var bookServiceModel = new InsertBookServiceModel
            {
                UserId        = userId, Name = request.Name, AuthorId = request.AuthorId
                , PublisherId = request.PublisherId, PublisherDate = request.PublisherDate
                , No          = request.No, SkinType = request.SkinType, Tag = request.Tag
                , LibraryId   = request.LibraryId, ShelfId = request.ShelfId
            };

            _bookService.InsertBook(bookServiceModel);

            return(StatusCode((int)HttpStatusCode.Created));
        }
Ejemplo n.º 2
0
        public void InsertBook(InsertBookServiceModel input)
        {
            var validator = new InsertBookServiceModelValidator();

            validator.ValidateAndThrow(input);

            var record = _bookRepository.Insert(new EBook
            {
                UserId        = input.UserId, Name = input.Name, AuthorId = input.AuthorId
                , PublisherId = input.PublisherId, PublishDate = input.PublisherDate
                , No          = input.No, SkinType = (int)input.SkinType, Tag = input.Tag
                , LibraryId   = input.LibraryId, ShelfId = input.ShelfId
            });

            _bookRepository.SaveChanges();

            _busControl.Publish(new BookCreated
            {
                BookId      = record.Id, AuthorId = input.AuthorId, PublisherId = input.PublisherId
                , LibraryId = input.LibraryId, ShelfId = input.ShelfId
            }).GetAwaiter().GetResult();
        }
Ejemplo n.º 3
0
 public void WhenInputIsNotValidated_ThrowValidationException(InsertBookServiceModel input)
 {
     Assert.Throws <ValidationException>(() => _bookService.InsertBook(input));
 }