Ejemplo n.º 1
0
        public async Task <IActionResult> GetAllBookListing([FromQuery] PaginationInputDto input, CancellationToken cancellationToken)
        {
            var result   = new List <BookListingDto>();
            var groupped = _dbContext.ListingBooks
                           .AsNoTracking()
                           .Include(x => x.Book)
                           .Include(x => x.Listing)
                           .OrderByDescending(x => x.Listing.DisplayOrder)
                           .AsEnumerable()
                           .GroupBy(x => x.Listing.Title)
                           .Skip(input.Page - 1)
                           .Take(input.Page * input.PageSize);

            //TODO: fix this! jsut for client side test!
            foreach (var item in groupped)
            {
                var toAdd = new BookListingDto
                {
                    ListingTitle = item.Key.Val,
                    Books        = new List <BookDto>()
                };
                foreach (var book in item)
                {
                    toAdd.Books.Add(new BookDto
                    {
                        AuthorName  = book.Book.AuthorName,
                        CoverImage  = book.Book.CoverImage,
                        Descripion  = book.Book.Descripion,
                        Name        = book.Book.Name.Val,
                        PageCount   = book.Book.PageCount,
                        Price       = book.Book.Price.Val,
                        PublishedOn = book.Book.PublishedOn,
                        Publisher   = book.Book.Publisher,
                        Title       = book.Book.Title.Val,
                        Translator  = book.Book.Translator
                    });
                }
                result.Add(toAdd);
            }



            return(Ok(result));
        }
Ejemplo n.º 2
0
        public CollectionResponseDto <ContactDto> FindAll(PaginationInputDto input)
        {
            if (input.SkipCount < 0)
            {
                input.SkipCount = 0;
            }

            if (input.MaxCount < 0)
            {
                input.MaxCount = 0;
            }

            var entities     = this._repository.FindAll();
            var propertyInfo = typeof(Contact).GetProperty(input.SortBy);
            var result       = entities.OrderBy(t => propertyInfo.GetValue(t, null)).Skip(input.SkipCount).Take(input.MaxCount).ToList();
            var response     = new CollectionResponseDto <ContactDto> {
                SourceTotal = entities.Count()
            };
            var items = Mapper.Map <List <ContactDto> >(result);

            response.Items.AddRange(items);
            return(response);
        }