Пример #1
0
        public void Can_Get_All_Pending_Tasks()
        {
            _service.InsertTask(Scaffold.Task());
            _service.InsertTask(Scaffold.Task());
            _service.InsertTask(Scaffold.Task());
            _service.InsertTask(Scaffold.Task());

            Assert.Equal(4, _service.GetAllPendingTasks(new [] { 1, 2, 3 }).Count);
        }
        public async Task <IHttpActionResult> GetFlowsForUser(int userId, int type, int count, int page)
        {
            try
            {
                List <WorkflowTaskPoco> taskInstances = (type == 0
                    ? _tasksService.GetAllPendingTasks(new List <int>
                {
                    (int)TaskStatus.PendingApproval, (int)TaskStatus.Rejected
                })
                    : _tasksService.GetTaskSubmissionsForUser(userId, new List <int>
                {
                    (int)TaskStatus.PendingApproval, (int)TaskStatus.Rejected
                }))
                                                        .Where(x => x.WorkflowInstance.Active)
                                                        .ToList();


                if (type == 0)
                {
                    foreach (WorkflowTaskPoco taskInstance in taskInstances)
                    {
                        taskInstance.UserGroup = await _groupService.GetPopulatedUserGroupAsync(taskInstance.UserGroup.GroupId);
                    }

                    taskInstances = taskInstances.Where(x =>
                                                        x.UserGroup.IsMember(userId) ||
                                                        x.Status == (int)TaskStatus.Rejected && x.WorkflowInstance.AuthorUserId == userId).ToList();
                }

                taskInstances = taskInstances.Where(x => x.WorkflowInstance.Node != null && !x.WorkflowInstance.Node.Path.Contains(UmbConstants.System.RecycleBinContentString)).ToList();
                List <WorkflowTaskViewModel> workflowItems = _tasksService.ConvertToWorkflowTaskList(taskInstances.Skip((page - 1) * count).Take(count).ToList(), false);

                return(Json(new
                {
                    items = workflowItems,
                    totalPages = (int)Math.Ceiling((double)taskInstances.Count / count),
                    page,
                    count
                }, ViewHelpers.CamelCase));
            }
            catch (Exception ex)
            {
                string msg = $"Error trying to build user workflow tasks list for user {userId}";
                Log.Error(msg, ex);
                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg)));
            }
        }
Пример #3
0
        public async Task <IHttpActionResult> GetFlowsForUser(int userId, int type, int count, int page)
        {
            try
            {
                List <WorkflowTaskInstancePoco> taskInstances = type == 0
                    ? _tasksService.GetAllPendingTasks(new List <int> {
                    (int)TaskStatus.PendingApproval
                })
                    : _tasksService.GetTaskSubmissionsForUser(userId, new List <int> {
                    (int)TaskStatus.PendingApproval, (int)TaskStatus.Rejected
                });

                if (type == 0)
                {
                    foreach (WorkflowTaskInstancePoco taskInstance in taskInstances)
                    {
                        taskInstance.UserGroup = await _groupService.GetPopulatedUserGroupAsync(taskInstance.UserGroup.GroupId);
                    }

                    taskInstances = taskInstances.Where(x => x.UserGroup.IsMember(userId)).ToList();
                }

                List <WorkflowTask> workflowItems = _tasksService.ConvertToWorkflowTaskList(taskInstances.Skip((page - 1) * count).Take(count).ToList());

                return(Json(new
                {
                    items = workflowItems,
                    total = taskInstances.Count,
                    page,
                    count
                }, ViewHelpers.CamelCase));
            }
            catch (Exception ex)
            {
                string msg = $"Error trying to build user workflow tasks list for user {userId}";
                Log.Error(msg, ex);
                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg)));
            }
        }