Exemplo n.º 1
0
        public async Task Should_Return_Correct_Books_Off_All_Offices()
        {
            MockBooksByOffice();
            var options = new BooksByOfficeOptionsDto {
                OrganizationId = 2, Page = 1
            };
            var res = await _bookService.GetBooksByOfficeAsync(options);

            Assert.AreEqual(res.ItemCount, 3);
        }
Exemplo n.º 2
0
        public async Task Should_Return_Correct_Books_By_Office_Search_Results()
        {
            MockBooksByOffice();
            var options = new BooksByOfficeOptionsDto {
                OrganizationId = 2, OfficeId = 1, Page = 1, UserId = "testUserId", SearchString = "search"
            };
            var res = await _bookService.GetBooksByOfficeAsync(options);

            Assert.AreEqual(res.ItemCount, 1);
            Assert.AreEqual(res.Entries.First().Title, "Test2search");
        }
Exemplo n.º 3
0
        public async Task Should_Return_Books_By_Office()
        {
            MockBooksByOffice();
            var options = new BooksByOfficeOptionsDto {
                OrganizationId = 2, OfficeId = 1, Page = 1, UserId = "testUserId"
            };
            var res = await _bookService.GetBooksByOfficeAsync(options);

            Assert.AreEqual(res.ItemCount, 2);
            Assert.AreEqual(res.Entries.First().QuantityLeft, 1);
            Assert.AreEqual(res.Entries.First().Readers.First().Id, "testUserId");
            Assert.IsTrue(res.Entries.First().TakenByCurrentUser);
        }
Exemplo n.º 4
0
        public async Task <IHttpActionResult> GetBooksByOffice(int officeId, int page = 1, string searchString = null)
        {
            if (!string.IsNullOrEmpty(searchString) && searchString.Length < BusinessLayerConstants.MinCharactersInBookSearch || officeId < 1)
            {
                return(BadRequest());
            }

            var options = new BooksByOfficeOptionsDto
            {
                OfficeId     = officeId,
                Page         = page,
                SearchString = searchString
            };

            SetOrganizationAndUser(options);

            var books = await _bookService.GetBooksByOfficeAsync(options);

            var result = _mapper.Map <ILazyPaged <BooksByOfficeDto>, ILazyPaged <BooksByOfficeViewModel> >(books);

            return(Ok(result));
        }
Exemplo n.º 5
0
        public async Task <ILazyPaged <BooksByOfficeDto> > GetBooksByOfficeAsync(BooksByOfficeOptionsDto options)
        {
            var allBooks = _bookOfficesDbSet
                           .Include(x => x.Book)
                           .Include(x => x.BookLogs.Select(v => v.ApplicationUser))
                           .Where(x => x.OrganizationId == options.OrganizationId && x.Quantity != 0)
                           .Where(OfficeFilter(options.OfficeId))
                           .Where(SearchFilter(options.SearchString))
                           .OrderBy(x => x.Book.Title)
                           .Select(MapBooksWithReadersToDto(options.UserId));

            var totalBooksCount = await allBooks.CountAsync();

            var entriesCountToSkip = EntriesCountToSkip(options.Page);
            var books = await allBooks
                        .Skip(() => entriesCountToSkip)
                        .Take(() => BusinessLayerConstants.BooksPerPage)
                        .ToListAsync();

            var pageDto = new LazyPaged <BooksByOfficeDto>(books, options.Page, BusinessLayerConstants.BooksPerPage, totalBooksCount);

            return(pageDto);
        }