コード例 #1
0
ファイル: BookServiceTests.cs プロジェクト: nevaldas/simoona
        public void 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 = _bookService.GetBooksByOffice(options);

            Assert.AreEqual(res.ItemCount, 1);
            Assert.AreEqual(res.Entries.First().Title, "Test2search");
        }
コード例 #2
0
        public void Should_Return_Books_By_Office()
        {
            MockBooksByOffice();
            var options = new BooksByOfficeOptionsDTO {
                OrganizationId = 2, OfficeId = 1, Page = 1, UserId = "testUserId"
            };
            var res = _bookService.GetBooksByOffice(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);
        }
コード例 #3
0
        public ILazyPaged <BooksByOfficeDTO> GetBooksByOffice(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    = allBooks.Count();
            int entriesCountToSkip = EntriesCountToSkip(options.Page);
            var books = allBooks
                        .Skip(() => entriesCountToSkip)
                        .Take(() => ConstBusinessLayer.BooksPerPage)
                        .ToList();

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

            return(pageDto);
        }
コード例 #4
0
        public IHttpActionResult GetBooksByOffice(int officeId, int page = 1, string searchString = null)
        {
            if (!string.IsNullOrEmpty(searchString) &&
                searchString.Length < ConstBusinessLayer.MinCharactersInBookSearch ||
                officeId < 1)
            {
                return(BadRequest());
            }

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

            SetOrganizationAndUser(options);

            var bookDtos = _bookService.GetBooksByOffice(options);
            var result   = _mapper.Map <ILazyPaged <BooksByOfficeDTO>, ILazyPaged <BooksByOfficeViewModel> >(bookDtos);

            return(Ok(result));
        }