예제 #1
0
        public void FilterSubmissions_UserAndDateSpecified_ReturnsUserSubmissionsForAssignmentThroughDate()
        {
            var assignments = CreateAssignments(1);
            var user        = new User()
            {
                Id = 10
            };
            var submissions = Collections.CreateList
                              (
                CreateSubmission(assignmentId: 1, userId: 10, dateSubmitted: GetDate(1)),
                CreateSubmission(assignmentId: 1, userId: 20, dateSubmitted: GetDate(1)),
                CreateSubmission(assignmentId: 2, userId: 10, dateSubmitted: GetDate(2))
                              );

            var assignmentFilter = new AssignmentFilter();
            var results          = assignmentFilter.FilterSubmissions
                                   (
                assignments,
                submissions,
                user,
                snapshotDate: GetDate(1)
                                   );

            Assert.Equal(1, results.Count);
            Assert.Equal(submissions[0], results[0]);
        }
예제 #2
0
        public void FilterAssignments_OnlySectionGiven_FiltersToAssignedInSection()
        {
            var section1 = new Section()
            {
                Id = 1
            };
            var section2 = new Section()
            {
                Id = 2
            };
            var assignments = Collections.CreateList
                              (
                CreateAssignment("Group2", section1, GetDate(5)),
                CreateAssignment("Group1", section1, GetDate(5)),
                CreateAssignment("Group1", section1, GetDate(4)),
                CreateAssignment("Group1", section2, GetDate(2)),
                CreateAssignment("Group2", section2, GetDate(1)),
                CreateAssignment("Group1", section: null, dueDate: null)
                              );

            var assignmentFilter = new AssignmentFilter();
            var results          = assignmentFilter.FilterAssignments
                                   (
                assignments,
                section1,
                assignmentGroupName: null
                                   );

            Assert.Equal(3, results.Count);
            Assert.Equal(assignments[2], results[0]);
            Assert.Equal(assignments[1], results[1]);
            Assert.Equal(assignments[0], results[2]);
        }
예제 #3
0
        public void FilterAssignments_OnlyGroupNameGiven_ReturnsAllInGroup()
        {
            var section1 = new Section()
            {
                Id = 1
            };
            var section2 = new Section()
            {
                Id = 2
            };
            var assignments = Collections.CreateList
                              (
                CreateAssignment("Group1", section1, GetDate(5)),
                CreateAssignment("Group1", section1, GetDate(4)),
                CreateAssignment("Group2", section1, GetDate(3)),
                CreateAssignment("Group1", section2, GetDate(2)),
                CreateAssignment("Group2", section2, GetDate(1)),
                CreateAssignment("Group1", section: null, dueDate: null)
                              );

            var assignmentFilter = new AssignmentFilter();
            var results          = assignmentFilter.FilterAssignments
                                   (
                assignments,
                null /*section*/,
                "Group1"
                                   );

            Assert.Equal(4, results.Count);
            Assert.Equal(assignments[3], results[0]);
            Assert.Equal(assignments[1], results[1]);
            Assert.Equal(assignments[0], results[2]);
            Assert.Equal(assignments[5], results[3]);
        }
예제 #4
0
        public void FilterSubmissions_UserSpecified_ReturnsUserSubmissionsForAssignment()
        {
            var assignments = CreateAssignments(1);
            var user        = new User()
            {
                Id = 10
            };
            var submissions = Collections.CreateList
                              (
                CreateSubmission(assignmentId: 1, userId: 10),
                CreateSubmission(assignmentId: 1, userId: 20),
                CreateSubmission(assignmentId: 2, userId: 10)
                              );

            var assignmentFilter = new AssignmentFilter();
            var results          = assignmentFilter.FilterSubmissions
                                   (
                assignments,
                submissions,
                user
                                   );

            Assert.Equal(1, results.Count);
            Assert.Equal(submissions[0], results[0]);
        }
예제 #5
0
        public void FilterAssignments_GroupNameAndSectionGiven_ReturnsAssignedInGroupToSection()
        {
            var section1 = new Section()
            {
                Id = 1
            };
            var section2 = new Section()
            {
                Id = 2
            };
            var assignments = Collections.CreateList
                              (
                CreateAssignment("Group1", section1, GetDate(5)),
                CreateAssignment("Group1", section1, GetDate(4)),
                CreateAssignment("Group2", section1, GetDate(3)),
                CreateAssignment("Group1", section2, GetDate(2)),
                CreateAssignment("Group2", section2, GetDate(1)),
                CreateAssignment("Group1", section: null, dueDate: null)
                              );

            var assignmentFilter = new AssignmentFilter();
            var results          = assignmentFilter.FilterAssignments
                                   (
                assignments,
                section1,
                "Group1"
                                   );

            Assert.Equal(2, results.Count);
            Assert.Equal(assignments[1], results[0]);
            Assert.Equal(assignments[0], results[1]);
        }
예제 #6
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)));
        }
예제 #7
0
        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)));
        }
        private static Dictionary <string, AssignmentFilter> GenerateFilters(string identityId)
        {
            var assignmentFilters = new Dictionary <string, AssignmentFilter>();
            var filterByExecutor  = new AssignmentFilter().ExecutorEquals(identityId);

            var filterByExecutorAndActive = new AssignmentFilter().ExecutorEquals(identityId).IsDeleted(false).IsActive(true);

            var filterByObserver = new AssignmentFilter().IsObserver(identityId).IsDeleted(false);

            assignmentFilters.Add("All assigned to me", filterByExecutor);
            assignmentFilters.Add("Active and assigned to me", filterByExecutorAndActive);
            assignmentFilters.Add("All", new AssignmentFilter());
            assignmentFilters.Add("I am observer", filterByObserver);

            return(assignmentFilters);
        }
예제 #9
0
        public AssignmentFilterModel GetFilterModel()
        {
            if (IsPostBack)
            {
                return(GetAssignmentsWithCustomFilter());
            }

            var filter = new AssignmentFilter();
            int count  = WorkflowInit.Runtime.PersistenceProvider.GetAssignmentCountAsync(filter).Result;
            List <Assignment> assignments = WorkflowInit.Runtime.AssignmentApi.GetAssignmentsAsync(filter, new Paging(1, PageSize)).Result;

            Count      = count;
            PageNumber = 1;
            AssignmentsTableRepeater.DataSource = GetAssignmentModels(assignments);
            AssignmentsTableRepeater.DataBind();

            return(new AssignmentFilterModel());
        }
예제 #10
0
        public void FilterSubmissions_NoUserOrDateSpecified_ReturnsSubmissionsForAssignment()
        {
            var assignments = CreateAssignments(1);
            var submissions = Collections.CreateList
                              (
                CreateSubmission(assignmentId: 1),
                CreateSubmission(assignmentId: 1),
                CreateSubmission(assignmentId: 2)
                              );

            var assignmentFilter = new AssignmentFilter();
            var results          = assignmentFilter.FilterSubmissions
                                   (
                assignments,
                submissions
                                   );

            Assert.Equal(2, results.Count);
            Assert.Equal(submissions[0], results[0]);
            Assert.Equal(submissions[1], results[1]);
        }
예제 #11
0
        public void GetAssignmentGroups_ReturnsGroupsOrderedByLastDueDateThenName()
        {
            var section = new Section()
            {
                Id = 1
            };
            var assignments = Collections.CreateList
                              (
                CreateAssignment("Group1", section: null, dueDate: null),
                CreateAssignment("Group1", section, GetDate(1)),
                CreateAssignment("Group2", section, GetDate(5)),
                CreateAssignment("Group2", section, GetDate(4)),
                CreateAssignment("Group3", section, GetDate(5)),
                CreateAssignment("Group2", section, GetDate(2))
                              );

            var assignmentFilter = new AssignmentFilter();
            var results          = assignmentFilter.GetAssignmentGroups
                                   (
                section,
                assignments
                                   );

            Assert.Equal(3, results.Count);

            Assert.Equal("Group2", results[0].Key);
            Assert.Equal(3, results[0].Count());
            Assert.Equal(assignments[2], results[0].ElementAt(0));
            Assert.Equal(assignments[3], results[0].ElementAt(1));
            Assert.Equal(assignments[5], results[0].ElementAt(2));

            Assert.Equal("Group3", results[1].Key);
            Assert.Single(results[1]);
            Assert.Equal(assignments[4], results[1].ElementAt(0));

            Assert.Equal("Group1", results[2].Key);
            Assert.Equal(2, results[2].Count());
            Assert.Equal(assignments[0], results[2].ElementAt(0));
            Assert.Equal(assignments[1], results[2].ElementAt(1));
        }
예제 #12
0
        public void FilterAssignments_NeitherGroupNameNorSectionGiven_ReturnsAllAssignments()
        {
            var section1 = new Section()
            {
                Id = 1
            };
            var section2 = new Section()
            {
                Id = 2
            };
            var assignments = Collections.CreateList
                              (
                CreateAssignment("Group1", section1, GetDate(5)),
                CreateAssignment("Group1", section1, GetDate(4)),
                CreateAssignment("Group2", section1, GetDate(3)),
                CreateAssignment("Group1", section2, GetDate(2)),
                CreateAssignment("Group2", section2, GetDate(1)),
                CreateAssignment("Group1", section: null, dueDate: null)
                              );

            var assignmentFilter = new AssignmentFilter();
            var results          = assignmentFilter.FilterAssignments
                                   (
                assignments,
                section: null,
                assignmentGroupName: null
                                   );

            Assert.Equal(6, results.Count);
            Assert.Equal(assignments[4], results[0]);
            Assert.Equal(assignments[3], results[1]);
            Assert.Equal(assignments[2], results[2]);
            Assert.Equal(assignments[1], results[3]);
            Assert.Equal(assignments[0], results[4]);
            Assert.Equal(assignments[5], results[5]);
        }
예제 #13
0
        public async Task <Page <BookPageModel> > GetPagesByBook(int libraryId, int bookId, int pageNumber, int pageSize, EditingStatus status, AssignmentFilter assignmentFilter, AssignmentFilter reviewerAssignmentFilter, int?assignedTo, 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.BookId = @BookId
                            AND (@Status = -1 OR p.Status = @Status )
                            AND (
                                ( @AssignmentFilter = 0 ) OR
                                ( @AssignmentFilter = 1 AND p.WriterAccountId IS NOT NULL) OR
                                ( @AssignmentFilter = 2 AND p.WriterAccountId IS NULL) OR
                                ( (@AssignmentFilter = 3  OR @AssignmentFilter = 4) AND p.WriterAccountId = @AccountId )
                            )
                            AND (
                                ( @ReviewerAssignmentFilter = 0 ) OR
                                ( @ReviewerAssignmentFilter = 1 AND p.ReviewerAccountId IS NOT NULL) OR
                                ( @ReviewerAssignmentFilter = 2 AND p.ReviewerAccountId IS NULL) OR
                                ( (@ReviewerAssignmentFilter = 3  OR @ReviewerAssignmentFilter = 4) AND p.ReviewerAccountId = @AccountId )
                            )
                            ORDER BY p.SequenceNumber
                            OFFSET @PageSize * (@PageNumber - 1) ROWS
                            FETCH NEXT @PageSize ROWS ONLY";
                var command = new CommandDefinition(sql,
                                                    new
                {
                    LibraryId                = libraryId,
                    BookId                   = bookId,
                    Status                   = status,
                    PageSize                 = pageSize,
                    PageNumber               = pageNumber,
                    AssignmentFilter         = assignmentFilter,
                    ReviewerAssignmentFilter = reviewerAssignmentFilter,
                    AccountId                = assignedTo
                },
                                                    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.BookId = @BookId
                                AND (@Status = -1 OR p.Status = @Status )
                                AND (
                                    ( @AssignmentFilter = 0 ) OR
                                    ( @AssignmentFilter = 1 AND p.WriterAccountId IS NOT NULL) OR
                                    ( @AssignmentFilter = 2 AND p.WriterAccountId IS NULL) OR
                                    ( (@AssignmentFilter = 3  OR @AssignmentFilter = 4) AND p.WriterAccountId = @AccountId )
                                )
                                AND (
                                ( @ReviewerAssignmentFilter = 0 ) OR
                                ( @ReviewerAssignmentFilter = 1 AND p.ReviewerAccountId IS NOT NULL) OR
                                ( @ReviewerAssignmentFilter = 2 AND p.ReviewerAccountId IS NULL) OR
                                ( (@ReviewerAssignmentFilter = 3  OR @ReviewerAssignmentFilter = 4) AND p.ReviewerAccountId = @AccountId )
                            )";
                var commandCount = new CommandDefinition(sqlCount, new
                {
                    LibraryId                = libraryId,
                    BookId                   = bookId,
                    Status                   = status,
                    AssignmentFilter         = assignmentFilter,
                    ReviewerAssignmentFilter = reviewerAssignmentFilter,
                    AccountId                = assignedTo
                },
                                                         cancellationToken: cancellationToken);

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

                return(new Page <BookPageModel>
                {
                    PageNumber = pageNumber,
                    PageSize = pageSize,
                    TotalCount = pagesCount,
                    Data = pages
                });
            }
        }
        public ActionResult Assignments(AssignmentFilterModel model = null)
        {
            var identityId = CurrentUserSettings.GetCurrentUser(HttpContext).ToString();

            AssignmentFilter customFilter;

            var assignmentFilters = GenerateFilters(identityId);

            if (model != null && assignmentFilters.TryGetValue(model.FilterName, out var res))
            {
                customFilter = res;

                if (model.DocumentNumber != null)
                {
                    var doc = _documentRepository.GetByNumber((int)model.DocumentNumber);
                    if (doc != null)
                    {
                        customFilter.ProcessIdEqual(doc.Id);
                    }
                    else
                    {
                        customFilter.ProcessIdEqual(Guid.Empty);
                    }
                }
                if (model.AssignmentCode != null)
                {
                    customFilter.CodeEquals(model.AssignmentCode);
                }
                if (model.StatusState != "Any")
                {
                    customFilter.StatusStateEquals(model.StatusState);
                }
            }
            else
            {
                customFilter = new AssignmentFilter();
                model        = new AssignmentFilterModel()
                {
                    Page = model?.Page ?? 1, PageChanged = 0
                };
            }

            int count = WorkflowInit.Runtime.PersistenceProvider.GetAssignmentCountAsync(customFilter).Result;

            model.Page = model?.Page ?? 1;
            var maxPage = Math.Ceiling(count / (decimal)pageSize);

            if (model.Page > maxPage)
            {
                model.Page = (int)maxPage;
            }

            List <Assignment> assignments = WorkflowInit.Runtime.AssignmentApi.GetAssignmentsAsync(customFilter, new Paging(model.Page, pageSize)).Result;

            var statuses = WorkflowInit.Runtime.AssignmentApi.GetAssignmentStatuses();

            statuses.Add("Any");

            return(View("Assignments", new AssignmentListModel()
            {
                Assignments = GetAssignmentModels(assignments),
                PageSize = pageSize,
                Count = count,
                Filters = assignmentFilters,
                CustomFilter = model,
                Statuses = statuses
            }));
        }
예제 #15
0
        private AssignmentFilterModel GetAssignmentsWithCustomFilter()
        {
            var model = new AssignmentFilterModel()
            {
                FilterName     = Request.Form[$"{Master.UniqueID}$MainContent$formFilter$FilterName"],
                AssignmentCode = Request.Form[$"{Master.UniqueID}$MainContent$formFilter$AssignmentCode"],
                StatusState    = Request.Form[$"{Master.UniqueID}$MainContent$formFilter$StatusState"],
                Page           = Int32.Parse(Request.Form[$"{Master.UniqueID}$MainContent$formFilter$Page"]),
            };

            var isCorrect = Int32.TryParse(Request.Form[$"{Master.UniqueID}$MainContent$formFilter$DocumentNumber"], out int documentNumber);

            model.DocumentNumber = isCorrect ? documentNumber : (int?)null;

            Guid identityId        = CurrentUserSettings.GetCurrentUser();
            var  assignmentFilters = GenerateFilters(identityId.ToString());

            AssignmentFilter customFilter;

            if (assignmentFilters.TryGetValue(model.FilterName, out var res))
            {
                customFilter = res;

                if (model.DocumentNumber != null)
                {
                    var doc = DocumentRepository.GetByNumber((int)model.DocumentNumber);
                    if (doc != null)
                    {
                        customFilter.ProcessIdEqual(doc.Id);
                    }
                    else
                    {
                        customFilter.ProcessIdEqual(Guid.Empty);
                    }
                }
                if (!model.AssignmentCode.IsNullOrWhiteSpace())
                {
                    customFilter.CodeEquals(model.AssignmentCode);
                }
                if (model.StatusState != "Any")
                {
                    customFilter.StatusStateEquals(model.StatusState);
                }
            }
            else
            {
                customFilter = new AssignmentFilter();
                model        = new AssignmentFilterModel()
                {
                    Page = model?.Page ?? 1
                };
            }

            int count = WorkflowInit.Runtime.PersistenceProvider.GetAssignmentCountAsync(customFilter).Result;

            model.Page = model?.Page ?? 1;
            var maxPage = Math.Ceiling(count / (decimal)PageSize);

            if (model.Page > maxPage)
            {
                model.Page = (int)maxPage;
            }

            List <Assignment> assignments = WorkflowInit.Runtime.AssignmentApi.GetAssignmentsAsync(customFilter, new Paging(model.Page, PageSize)).Result;

            Count      = count;
            PageNumber = model.Page;
            AssignmentsTableRepeater.DataSource = GetAssignmentModels(assignments);
            AssignmentsTableRepeater.DataBind();

            return(model);
        }