public IPageResult <Models.Log> GetPageList(string Filter, string Sort, int PageNumber = 1, int PageSize = 20, params object[] Values)
        {
            var query = repository.Query();

            if (!Filter.IsNull())
            {
                query = query.Where(Filter, Values);
            }
            if (!Sort.IsNull())
            {
                query = query.SortBy(Sort);
            }
            long count = 0;
            var  items = query.Page(PageNumber, PageSize, out count).ToList().Select(entity => Mapper.Map <Models.Log>(entity)).ToList();

            var response = new IPageResult <Models.Log>()
            {
                Result = new PagedResult <Models.Log>
                {
                    CurrentPage = PageNumber,
                    TotalItems  = count,
                    PageSize    = PageSize,
                    Items       = items
                }
            };

            return(response);
        }
Beispiel #2
0
        /// <summary>
        /// 分页集合Dto
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pageResult"></param>
        /// <returns></returns>
        public static PageList <T> PageList <T>(this IPageResult <T> pageResult)
        {
            var result = pageResult;

            return(new PageList <T>()
            {
                Data = result.Data, Message = result.Message, Total = result.Total, Success = result.Success
            });
        }
Beispiel #3
0
        //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)
            });
        }
Beispiel #4
0
        public async Task GetOrders_ShouldGet_Orders(OrderSpecification orderSpecification, int index, int pageSize, int count)
        {
            _repository.Setup(s => s.GetListAsync(It.IsAny <Expression <Func <Order, bool> > >(), It.IsAny <Func <IQueryable <Order>, IOrderedQueryable <Order> > >(), It.IsAny <Expression <Func <Order, object> > >()))
            .ReturnsAsync(DataSeed.Orders.AsQueryable().Where(orderSpecification));
            IPageResult <Order> orders = await _orderService.GetOrders(orderSpecification, index, pageSize);

            Assert.NotNull(orders);
            Assert.Equal(count, orders.Total);
            int pageCount = count - pageSize * index;

            Assert.Equal(pageCount >= pageSize ? pageSize : (pageCount > 0 ? count : 0), orders.Data.Count());
        }
Beispiel #5
0
        public async Task GetInvoices_Should_GetInvoices(InvoiceSpecification invoiceSpecification, int index, int pageSize, int count)
        {
            _repository.Setup(s => s.GetListAsync(It.IsAny <Expression <Func <Invoice, bool> > >(), It.IsAny <Func <IQueryable <Invoice>, IOrderedQueryable <Invoice> > >(), It.IsAny <Expression <Func <Invoice, object> > >()))
            .ReturnsAsync(DataSeed.Invoices.AsQueryable().Where(invoiceSpecification));
            IPageResult <Invoice> invoices = await _invoiceService.GetInvoices(invoiceSpecification, index, pageSize);

            Assert.NotNull(invoices);
            Assert.Equal(count, invoices.Total);
            int pageCount = count - pageSize * index;

            Assert.Equal(pageCount >= pageSize ? pageSize : (pageCount > 0 ? count : 0), invoices.Data.Count());
        }
        public async Task GetBooksPrice_Should_GetList(PriceSpecification specification, int index, int pageSize, int count)
        {
            _repository.Setup(s => s.GetListAsync(It.IsAny <Expression <Func <BookPrice, bool> > >(), It.IsAny <Func <IQueryable <BookPrice>, IOrderedQueryable <BookPrice> > >(), It.IsAny <Expression <Func <BookPrice, object> > >()))
            .ReturnsAsync(DataSeed.BookPrices.AsQueryable().Where(specification));
            IPageResult <BookPrice> price = await _priceService.GetPriceList(specification, index, pageSize);

            Assert.NotNull(price);
            Assert.Equal(count, price.Total);
            int pageCount = count - pageSize * index;

            Assert.Equal(pageCount >= pageSize ? pageSize : (pageCount > 0 ? count : 0), price.Data.Count());
        }
        public async Task GetProductsForCategoryAsync_PositiveTests(int categoryID, int pageNo, int pageSize, int expectedTotalCount, int expectedTotalPages, int expectedItemCount)
        {
            CancellationToken cancellationToken = default(CancellationToken);

            var repo = new ProductRepository(_context);
            IPageResult <Product> result = await repo.GetProductsForCategoryAsync(categoryID, pageNo, pageSize, cancellationToken);

            Assert.True(result.PageSize == pageSize);
            Assert.True(result.PageNo == pageNo);
            Assert.True(result.TotalCount == expectedTotalCount);
            Assert.True(result.TotalPages == expectedTotalPages);
            Assert.True(result.Items.Count == expectedItemCount);
        }
Beispiel #8
0
        public async Task GetBooks_ShouldGet_CorrectBookList(BookSpecification specification, int index, int pageSize, int count)
        {
            IQueryable <Book> bookQueryable = DataSeed.Books.AsQueryable().Where(specification);

            _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(bookQueryable);
            IPageResult <Book> books = await _bookService.GetBooks(specification, index, pageSize);

            Assert.NotNull(books);
            Assert.Equal(count, books.Total);
            int pageCount = count - pageSize * index;

            Assert.Equal(pageCount >= pageSize ? pageSize : (pageCount > 0 ? count : 0), books.Data.Count());
        }
Beispiel #9
0
        //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
            });
        }
Beispiel #10
0
        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());
        }
Beispiel #11
0
        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());
        }
Beispiel #12
0
 public Builder(List <TEntity> data)
 {
     _result = new PageResult <TEntity> {
         Data = data
     };
 }