public BookOutputDto GetBookListByUserId(int userId) { BookOutputDto bookoutput = new BookOutputDto(); var books = _bookRepository.GetBooksWithUserId(userId).ToList(); if (books.Any()) { foreach (var eBook in books) { BookDto book = new BookDto { Id = eBook.Id, Name = eBook.Name, Author = eBook.Author.Name, Publisher = eBook.Publisher.Name, Genre = eBook.Genre.Genre, No = eBook.No.ToString(), Rack = eBook.Rack.RackNumber, Shelf = eBook.Shelf.Name, SkinType = Enum.GetName(typeof(SkinType), eBook.SkinType), Serie = eBook.Serie != null ? eBook.Serie.Name : string.Empty, PublishDate = eBook.PublishDate, CreatedDateTime = eBook.CreatedDateTime }; bookoutput.Books.Add(book); } } return(bookoutput); }
public async Task <BookOutputDto> GetBookById(int id) { BookOutputDto book = new BookOutputDto(); var result = _bookManager.GetAsync(id); book = _mapper.Map <BookOutputDto>(result); return(book); }
public bool Update(BookUpdateDto bookUpdate, BookOutputDto bookOutput) { try { var bookUpdated = _mapper.Map(bookUpdate, bookOutput); var book = _mapper.Map <BookOutputDto, Book>(bookUpdated); _bookService.Update(book); return(Commit()); } catch (Exception ex) { throw; } }
public void WhenGetBookListMethodCall_ReturnsSuccess() { EBook demo = new EBook() { Id = 1, Name = "demo", Author = new EAuthor { Name = "" }, Publisher = new EPublisher { Name = "" }, Serie = new ESeries { Name = "" }, PublishDate = It.IsAny <int>(), Genre = new EGenre { Genre = "" }, No = 1, SkinType = Data.Entities.Enums.SkinType.Ciltli, Shelf = new EShelf { Name = "" }, Rack = new ERack { RackNumber = 1 }, CreatedDateTime = DateTime.Now, SeriesId = 0 }; _bookRepository.Setup(r => r.GetAll()).Returns( new List <EBook>() { demo }); _bookServiceApplication = new BookServiceApplication(_bookRepository.Object, _userRepository.Object); BookOutputDto output = _bookServiceApplication.GetBookList(); Assert.Collection <BookDto>(output.Books, t => Assert.Contains("demo", t.Name)); }
private BookOutputDto CreateLinksForBook(BookOutputDto book) { //HATEOAS: here we decide in which links should be returned when a consumer of the api gets back a book representation //Attention: in the new {id = book.Id} the anonymous type "id" must be the same of the parameter of the given method book.Links.Add(new LinkDto(_urlHelper.Link("GetBookForAuthor", new { id = book.Id }), "self", //this is the part that the consumer of the API have to know about, because that is this the will be used by the consumer to see a specific piece of functionality is offered by the api. "GET")); book.Links.Add(new LinkDto(_urlHelper.Link("DeleteBookForAuthor", new { id = book.Id }), "delete_book", //this is the part that the consumer of the API have to know about, because that is this the will be used by the consumer to see a specific piece of functionality is offered by the api. "DELETE")); book.Links.Add(new LinkDto(_urlHelper.Link("UpdateBookForAuthor", new { id = book.Id }), "udpdate_book", //this is the part that the consumer of the API have to know about, because that is this the will be used by the consumer to see a specific piece of functionality is offered by the api. "PUT")); book.Links.Add(new LinkDto(_urlHelper.Link("PartiallyUpdateBookForAuthor", new { id = book.Id }), "partially_update_book", //this is the part that the consumer of the API have to know about, because that is this the will be used by the consumer to see a specific piece of functionality is offered by the api. "PATCH")); return(book); }
public BookOutputDto GetBooksSearchRangeBy(int start, int length, string searchKey, int userId) { BookOutputDto bookoutput = new BookOutputDto(); // get book count for related user int count = _bookRepository.GetBooksSearchRangeBy(searchKey, userId).ToList().Count(); bookoutput.TotalBook = count; var books = _bookRepository.GetBooksSearchRangeBy(searchKey, userId).OrderBy(x => x.Name).Skip(start).Take(length).ToList(); if (books.Any()) { foreach (var eBook in books) { BookDto book = new BookDto { Id = eBook.Id, Name = eBook.Name, Author = eBook.Author.Name, Publisher = eBook.Publisher.Name, Genre = eBook.Genre.Genre, No = eBook.No.ToString(), Rack = eBook.Rack.RackNumber, Shelf = eBook.Shelf.Name, SkinType = Enum.GetName(typeof(SkinType), eBook.SkinType), Serie = eBook.Serie != null ? eBook.Serie.Name : string.Empty, PublishDate = eBook.PublishDate, CreatedDateTime = eBook.CreatedDateTime }; bookoutput.Books.Add(book); } } return(bookoutput); }