Exemple #1
0
        public async Task <IActionResult> GetPagesByUser(int libraryId,
                                                         int pageNumber = 1,
                                                         int pageSize   = 10,
                                                         [FromQuery] EditingStatus status = EditingStatus.All,
                                                         [FromQuery] AssignmentFilter assignmentFilter = AssignmentFilter.All,
                                                         CancellationToken token = default(CancellationToken))
        {
            var accountId         = _userHelper.Account.Id;
            var getBookPagesQuery = new GetUserPagesQuery(libraryId, accountId, pageNumber, pageSize)
            {
                StatusFilter = status,
            };
            var result = await _queryProcessor.ExecuteAsync(getBookPagesQuery, token);

            var args = new PageRendererArgs <BookPageModel, BookPageFilter>
            {
                Page           = result,
                RouteArguments = new PagedRouteArgs {
                    PageNumber = pageNumber, PageSize = pageSize
                },
                Filters = new BookPageFilter {
                    Status = status
                }
            };

            return(new OkObjectResult(_bookPageRenderer.RenderUserPages(args, libraryId)));
        }
        public async Task <IActionResult> GetPagesByBook(int libraryId,
                                                         int bookId,
                                                         int pageNumber = 1,
                                                         int pageSize   = 10,
                                                         [FromQuery] EditingStatus status = EditingStatus.All,
                                                         [FromQuery] AssignmentFilter assignmentFilter         = AssignmentFilter.All,
                                                         [FromQuery] AssignmentFilter reviewerAssignmentFilter = AssignmentFilter.All,
                                                         [FromQuery] int?assignmentTo = null,
                                                         CancellationToken token      = default(CancellationToken))
        {
            var getBookPagesQuery = new GetBookPagesQuery(libraryId, bookId, pageNumber, pageSize)
            {
                StatusFilter             = status,
                AssignmentFilter         = assignmentFilter,
                ReviewerAssignmentFilter = reviewerAssignmentFilter,
                AccountId = assignmentFilter == AssignmentFilter.AssignedToMe || reviewerAssignmentFilter == AssignmentFilter.AssignedToMe ? _userHelper.Account?.Id : assignmentTo
            };
            var result = await _queryProcessor.ExecuteAsync(getBookPagesQuery, token);

            var args = new PageRendererArgs <BookPageModel, BookPageFilter>
            {
                Page           = result,
                RouteArguments = new PagedRouteArgs {
                    PageNumber = pageNumber, PageSize = pageSize
                },
                Filters = new BookPageFilter {
                    Status = status, AssignmentFilter = assignmentFilter, ReviewerAssignmentFilter = reviewerAssignmentFilter, AccountId = assignmentTo
                }
            };

            return(new OkObjectResult(_bookPageRenderer.Render(args, libraryId, bookId)));
        }
        public async Task <BookPageModel> UpdatePage(int libraryId, int bookId, int sequenceNumber, string text, int imageId, EditingStatus status, int?chapterId, CancellationToken cancellationToken)
        {
            using (var connection = _connectionProvider.GetConnection())
            {
                var sql     = @"Update p
                            SET p.Text = @Text, 
                                p.ImageId = @ImageId, 
                                Status = @Status,
                                ChapterId = @ChapterId
                            FROM BookPage p
                            INNER JOIN Book b ON b.Id = p.BookId
                            WHERE b.LibraryId = @LibraryId AND p.BookId = @BookId AND p.SequenceNumber = @SequenceNumber";
                var command = new CommandDefinition(sql, new
                {
                    LibraryId      = libraryId,
                    Text           = text,
                    ImageId        = imageId,
                    BookId         = bookId,
                    SequenceNumber = sequenceNumber,
                    Status         = status,
                    ChapterId      = chapterId
                }, cancellationToken: cancellationToken);
                await connection.ExecuteAsync(command);

                return(await GetPageBySequenceNumber(libraryId, bookId, sequenceNumber, cancellationToken));
            }
        }
        public async Task <Page <BookPageModel> > GetPagesByUser(int libraryId, int accountId, EditingStatus statusFilter, int pageNumber, int pageSize, CancellationToken cancellationToken)
        {
            using (var connection = _connectionProvider.GetConnection())
            {
                var sql     = @"SELECT p.BookId, p.SequenceNumber, p.Status, 
                                   p.WriterAccountId, a.Name As WriterAccountName, p.WriterAssignTimeStamp,
                                   p.ReviewerAccountId, ar.Name As ReviewerAccountName, p.ReviewerAssignTimeStamp,
                                   f.Id As ImageId, f.FilePath AS ImageUrl, p.Text, p.ChapterId, c.Title As ChapterTitle
                            FROM BookPage AS p
                            LEFT OUTER JOIN [File] f ON f.Id = p.ImageId
                            LEFT OUTER JOIN [Chapter] c ON c.Id = p.ChapterId
                            INNER JOIN Book b ON b.Id = p.BookId
                            LEFT OUTER JOIN [Accounts] a ON a.Id = p.WriterAccountId
                            LEFT OUTER JOIN [Accounts] ar ON ar.Id = p.ReviewerAccountId
                            WHERE b.LibraryId = @LibraryId 
                            AND p.ReviewerAccountId = @AccountId OR p.WriterAccountId = @AccountId
                            AND (@Status = -1 OR p.Status = @Status )
                            ORDER BY p.BookId, p.SequenceNumber
                            OFFSET @PageSize * (@PageNumber - 1) ROWS
                            FETCH NEXT @PageSize ROWS ONLY";
                var command = new CommandDefinition(sql,
                                                    new
                {
                    LibraryId  = libraryId,
                    Status     = statusFilter,
                    PageSize   = pageSize,
                    PageNumber = pageNumber,
                    AccountId  = accountId
                },
                                                    cancellationToken: cancellationToken);

                var pages = await connection.QueryAsync <BookPageModel>(command);

                var sqlCount     = @"SELECT Count(*)
                                FROM BookPage p INNER JOIN Book b ON b.Id = p.BookId
                                WHERE b.LibraryId = @LibraryId 
                                AND p.ReviewerAccountId = @AccountId OR p.WriterAccountId = @AccountId
                                AND (@Status = -1 OR p.Status = @Status )";
                var commandCount = new CommandDefinition(sqlCount, new
                {
                    LibraryId = libraryId,
                    Status    = statusFilter,
                    AccountId = accountId
                },
                                                         cancellationToken: cancellationToken);

                var pagesCount = await connection.QuerySingleAsync <int>(commandCount);

                return(new Page <BookPageModel>
                {
                    PageNumber = pageNumber,
                    PageSize = pageSize,
                    TotalCount = pagesCount,
                    Data = pages
                });
            }
        }
Exemple #5
0
 public BooksDataBuilder WithStatus(EditingStatus statuses, int count)
 {
     _pageStatuses.TryAdd(statuses, count);
     return(this);
 }
Exemple #6
0
 public WhenGettingBookPagesInStatus(EditingStatus status)
     : base(Role.Reader)
 {
     _status = status;
 }