Exemplo n.º 1
0
        public async Task <IActionResult> Index(string sortorder, [FromServices] IDataSorter <QTask> sorter)
        {
            var result = await repositoryHandler.GetAllEntriesAsync();

            IEnumerable <QTask> assigneeTasks = await repositoryHandler.GetAllEntriesAsync(a => a.Assignee.FullName.Equals(User.Identity.Name));

            IEnumerable <QTask> reporterTasks = await repositoryHandler.GetAllEntriesAsync(r => r.Reporter.FullName.Equals(User.Identity.Name));

            IEnumerable <QTask> otherTasks = result.Except(assigneeTasks).Except(reporterTasks);

            if (!string.IsNullOrEmpty(sortorder))
            {
                assigneeTasks = sorter.Sort(assigneeTasks, sortorder);
                reporterTasks = sorter.Sort(reporterTasks, sortorder);
                otherTasks    = sorter.Sort(otherTasks, sortorder);
            }

            var model = new TaskIndexModel
            {
                PrioritySort     = sortorder == TaskSort.PriotityAsc ? TaskSort.PriotityDesc : TaskSort.PriotityAsc,
                NameSort         = sortorder == TaskSort.NameDesc ? string.Empty : TaskSort.NameDesc,
                StatusSort       = sortorder == TaskSort.StatusAsc ? TaskSort.StatusDesc : TaskSort.StatusAsc,
                AssigneeTaskList = assigneeTasks,
                ReporterTaskList = reporterTasks,
            };

            if (User.IsInRole(EmployeeRole.Admin.ToString()))
            {
                model.OtherTaskList = otherTasks;
            }

            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult Index(int[] projectId, int[] categoryId, int[] statusId, int?sprintId, int[] assignedTo, string completedDate, string modifiedDate, string createdDate, int?isArchived, string label, string text, string sortBy, string sortOrder)
        {
            var model = new TaskIndexModel();

            model.Tab = "Task";

            model.Projects           = DataHelper.GetProjectList();
            model.ProjectId          = projectId ?? new int[0];
            model.ProjectName        = DataHelper.ToString(model.Projects, model.ProjectId, "any project");
            model.ProjectDisplayName = DataHelper.Clip(model.ProjectName, 40);

            model.Categories          = DataHelper.GetCategoryList();
            model.CategoryId          = categoryId ?? new int[0];
            model.CategoryName        = DataHelper.ToString(model.Categories, model.CategoryId, "any category");
            model.CategoryDisplayName = DataHelper.Clip(model.CategoryName, 20);

            model.Statuses          = DataHelper.GetStatusList();
            model.StatusId          = statusId ?? new int[0];
            model.StatusName        = DataHelper.ToString(model.Statuses, model.StatusId, "any status");
            model.StatusDisplayName = DataHelper.Clip(model.StatusName, 20);

            model.AssignedToUsers       = DataHelper.GetUserList();
            model.AssignedTo            = assignedTo ?? new int[0];
            model.AssignedToName        = DataHelper.ToString(model.AssignedToUsers, model.AssignedTo, "any user");
            model.AssignedToDisplayName = DataHelper.Clip(model.AssignedToName, 20);

            model.Label      = label;
            model.IsArchived = isArchived ?? 0;

            model.Filters = MyService.FilterFetchInfoList("Task");

            model.SortBy    = sortBy ?? "TaskId";
            model.SortOrder = sortOrder ?? "ASC";
            model.SortableColumns.Add("EstimatedCompletedDate", "Due");
            model.SortableColumns.Add("ProjectName", "Project");
            model.SortableColumns.Add("AssignedToName", "User");
            model.SortableColumns.Add("StatusName", "Status");
            model.SortableColumns.Add("TaskId", "No.");

            model.LabelByCountListModel =
                new LabelByCountListModel
            {
                Action = "Task",
                Label  = label,
                Labels = DataHelper.GetTaskLabelByCountList()
            };

            var criteria = new TaskCriteria()
            {
                ProjectId     = projectId,
                SprintId      = sprintId,
                CategoryId    = categoryId,
                StatusId      = statusId,
                AssignedTo    = assignedTo,
                CompletedDate = new DateRangeCriteria(completedDate ?? string.Empty),
                ModifiedDate  = new DateRangeCriteria(modifiedDate ?? string.Empty),
                CreatedDate   = new DateRangeCriteria(createdDate ?? string.Empty),
                IsArchived    = DataHelper.ToBoolean(isArchived),
                TaskLabels    = string.IsNullOrEmpty(label) ? null : new[] { label },
                Text          = text
            };

            var tasks = TaskService.TaskFetchInfoList(criteria)
                        .AsQueryable();

            tasks = tasks.OrderBy(string.Format("{0} {1}", model.SortBy, model.SortOrder));

            model.Tasks = tasks;

            var hours = HourService.HourFetchInfoList(tasks.Cast <ITask>().ToArray());

            model.Hours = hours;

            return(RespondTo(format =>
            {
                format[RequestExtension.Html] = () => this.View(model);
                format[RequestExtension.Xml] = () => new XmlResult {
                    Data = model.Tasks.ToList(), TableName = "Task"
                };
                format[RequestExtension.Json] = () => new JsonResult {
                    Data = model.Tasks, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                };
            }));
        }