//public Task EditImage(UpdateBookDto dto) //{ // return _bookService.EditImage(dto.Id, dto.ImageBase64); //} //public Task EditRemark(UpdateBookDto dto) //{ // return _bookService.EditRemark(dto.Id, dto.Remark); //} public async Task <IPageResult <GetBookOutputDto> > GetBookList(GetBookInputDto dto) { Guard.Against.NegativeIndexPage(dto.PageSize, dto.Index); BookSpecification bookSpecification = new(dto.Title, dto.Author, dto.Publisher, dto.ISBN, dto.BookTypeId); IPageResult <Book> books = await _bookService.GetBooks(bookSpecification, dto.Index, dto.PageSize); return(new PageResult <GetBookOutputDto> { Total = books.Total, Data = _mapper.Map <List <GetBookOutputDto> >(books.Data) }); }
public async Task <PagedResultDto <BookDto> > GetAll(GetBookInputDto input) { var query = (await _repository.GetQueryableAsync()).WhereIf(!string.IsNullOrWhiteSpace(input.Filter), a => a.Name.Contains(input.Filter)); var totalCount = await query.CountAsync(); var items = await query.OrderBy(input.Sorting ?? "Id") .ToListAsync(); var dto = ObjectMapper.Map <List <Book>, List <BookDto> >(items); return(new PagedResultDto <BookDto>(totalCount, dto)); }
//public async Task EditBookPrice(UpdatePriceDto dto) //{ // await _priceService.EditBookPrice(dto.Id, dto.Price); //} public async Task <IPageResult <GetPriceOutputDto> > GetPriceList(GetBookInputDto dto) { Guard.Against.NegativeIndexPage(dto.PageSize, dto.Index); BookSpecification bookSpecification = new(dto.Title, dto.Author, dto.Publisher, dto.ISBN, dto.BookTypeId); var books = (await _bookRepository.GetListAsync(bookSpecification)).ToList(); IPageResult <BookPrice> price = await _priceService.GetPriceList(new PriceSpecification(books.Select(s => s.Id)), dto.Index, dto.PageSize); IEnumerable <GetPriceOutputDto> outputDto = price.Data.Join(books, bp => bp.BookId, b => b.Id, (bp, b) => new GetPriceOutputDto { BookTitle = b.Title, ISBN = b.ISBN, Price = bp.Price, Remark = bp.Remark, Id = bp.Id }); return(new PageResult <GetPriceOutputDto> { Total = price.Total, Data = outputDto }); }
public async Task GetBooks_ShouldGet_CorrectBookList(GetBookInputDto dto, int count) { BookSpecification bookSpecification = new(dto.Title, dto.Author, dto.Publisher, dto.ISBN, dto.BookTypeId); var bookList = DataSeed.Books.AsQueryable().Where(bookSpecification); _bookService.Setup(s => s.GetBooks(It.IsAny <BookSpecification>(), It.IsAny <int>(), It.IsAny <int>())) .ReturnsAsync(new PageResult <Book>(bookList, dto.Index, dto.PageSize)); IPageResult <GetBookOutputDto> books = await _bookViewService.GetBookList(dto); Assert.NotNull(books); Assert.Equal(count, books.Total); Assert.NotNull(books.Data); int pageCount = count - dto.PageSize * dto.Index; Assert.Equal(pageCount >= dto.PageSize ? dto.PageSize : (pageCount > 0 ? count : 0), books.Data.Count()); }
public async Task GetPriceList_Should_GetListDto(GetBookInputDto dto, int count) { BookSpecification bookSpecification = new(dto.Title, dto.Author, dto.Publisher, dto.ISBN, dto.BookTypeId); var books = DataSeed.Books.AsQueryable().Where(bookSpecification); PriceSpecification priceSpecification = new(books.Select(s => s.Id)); var prices = DataSeed.BookPrices.AsQueryable().Where(priceSpecification); _repository.Setup(s => s.GetListAsync(It.IsAny <Expression <Func <Book, bool> > >(), It.IsAny <Func <IQueryable <Book>, IOrderedQueryable <Book> > >(), It.IsAny <Expression <Func <Book, object> > >())) .ReturnsAsync(books); _priceService.Setup(s => s.GetPriceList(It.IsAny <PriceSpecification>(), It.IsAny <int>(), It.IsAny <int>())) .ReturnsAsync(new PageResult <BookPrice>(prices, dto.Index, dto.PageSize)); IPageResult <GetPriceOutputDto> result = await _priceViewService.GetPriceList(dto); Assert.NotNull(result); Assert.Equal(count, result.Total); Assert.NotNull(result.Data); int pageCount = count - dto.PageSize * dto.Index; Assert.Equal(pageCount >= dto.PageSize ? dto.PageSize : (pageCount > 0 ? count : 0), result.Data.Count()); }
public async Task <ActionResult <IPageResult <GetPriceOutputDto> > > GetPriceList([FromQuery] GetBookInputDto dto) { var result = await _priceViewService.GetPriceList(dto); return(Ok(result)); }
public Task <PagedResultDto <BookDto> > GetAll(GetBookInputDto input) { return(_BookAppService.GetAll(input)); }