Exemplo n.º 1
0
        // GET: Tasks
        public ActionResult Index(int teamId)
        {
            var date = DateTime.UtcNow;
            var tasksViewModel = new TasksViewModel();
            tasksViewModel.Date = date;

            var users = _userRepository.GetUsersForTeam(teamId).Select(u => new
            {
                u.FirstName,
                u.LastName,
                u.UserId
            }).OrderBy(u => u.FirstName).ThenBy(u => u.LastName).ToList();

            var allUsers = _userRepository.GetAllActiveUsers().Select(u => new
            {
                u.FirstName,
                u.LastName,
                u.UserId
            }).ToList() // First perform a query cause LINQ doesn't support the $ string method
            .Select(u => new
            {
                Name = $"{u.FirstName} {u.LastName}",
                u.UserId
            }).ToList();

            var allWorkflowSteps = _workflowStepRepository.GetAllTaskWorkflowSteps().ToList();

            var tasks = _taskRepository.GetTasksForTeamBeforeDay(teamId, date)
                .Select(t => new
                {
                    UserId = t.AssignedToId,
                    Title = t.Name,
                    RemainingHours = (t.RemainingUnitTypeId == 1 ? t.RemainingDuration / 60.0 : t.RemainingDuration),
                    t.ReportedById,
                    t.StartDate,
                    t.WorkflowStepId
                }).ToList();

            var taskUsers = new List<TasksViewModel.TaskUser>();
            foreach (var user in users)
            {
                var taskUser = new TasksViewModel.TaskUser();
                taskUser.Name = $"{user.FirstName} {user.LastName}";
                var userTasks = tasks.Where(t => t.UserId == user.UserId)
                    .Select(t => new TasksViewModel.Task
                    {
                        RemainingHours = t.RemainingHours,
                        StartDate = t.StartDate.Value,
                        Title = t.Title,
                        ReportedBy = allUsers.SingleOrDefault(u => u.UserId == t.ReportedById)?.Name,
                        WorkflowStep =
                            allWorkflowSteps.SingleOrDefault(w => w.WorkflowStepId == t.WorkflowStepId)?.StepName
                    });

                taskUser.Tasks = userTasks;
                taskUsers.Add(taskUser);
            }
            tasksViewModel.TaskUsers = taskUsers;

            return PartialView(tasksViewModel);
        }
Exemplo n.º 2
0
        // GET: Tasks
        public ActionResult Index(int teamId)
        {
            var date = DateTime.UtcNow.Date;
            var tasksViewModel = new TasksViewModel();
            tasksViewModel.Date = date;

            var users = _userRepository.GetUsersForTeam(teamId).Select(u => new
            {
                u.FirstName,
                u.LastName,
                u.UserId
            }).OrderBy(u => u.FirstName).ThenBy(u => u.LastName).ToList();

            var allUsers = _userRepository.GetAllActiveUsers().Select(u => new
            {
                u.FirstName,
                u.LastName,
                u.UserId
            }).ToList() // First perform a query cause LINQ doesn't support the $ string method
            .Select(u => new
            {
                Name = $"{u.FirstName} {u.LastName}",
                u.UserId
            }).ToList();

            var allWorkflowSteps = _workflowStepRepository.GetAllTaskWorkflowSteps().ToList();

            var tasks = _taskRepository.GetTasksForTeamBeforeDay(teamId, date)
                .Select(t => new
                {
                    UserId = t.AssignedToId,
                    Title = t.Name,
                    RemainingHours = (t.RemainingUnitTypeId == 1 ? t.RemainingDuration / 60.0 : t.RemainingDuration),
                    t.ReportedById,
                    t.StartDate,
                    t.DueDate,
                    t.WorkflowStepId,
                    t.ItemId
                }).ToList();

            var customFields = _taskRepository.GetCustomFieldsForTasks(tasks.Select(t => t.ItemId)).ToList();

            var taskUsers = new List<TasksViewModel.TaskUser>();
            foreach (var user in users)
            {
                var taskUser = new TasksViewModel.TaskUser();
                taskUser.Name = $"{user.FirstName} {user.LastName}";
                var userTasks = tasks.Where(t => t.UserId == user.UserId)
                    .OrderBy(t => t.Title)
                    .Select(t => new TasksViewModel.Task
                    {
                        Id = t.ItemId,
                        IsBlokTaak = customFields.SingleOrDefault(b => b.TaskId == t.ItemId)?.Custom_193 == "Bloktaak" ||
                        customFields.SingleOrDefault(b => b.TaskId == t.ItemId)?.Custom_193 == "Bloktaak - NIET BEVESTIGD",
                        IsVerlof = customFields.SingleOrDefault(b => b.TaskId == t.ItemId)?.Custom_193 == "Verlof",
                        RemainingHours = t.RemainingHours,
                        StartDate = t.StartDate.Value,
                        DueDate = t.DueDate > new DateTime(1899, 1, 1) ? (DateTime?)t.DueDate : null,
                        Title = t.Title,
                        ReportedBy = allUsers.SingleOrDefault(u => u.UserId == t.ReportedById)?.Name,
                        WorkflowStep =
                            allWorkflowSteps.SingleOrDefault(w => w.WorkflowStepId == t.WorkflowStepId)?.StepName
                    });

                taskUser.Tasks = userTasks;
                taskUsers.Add(taskUser);
            }
            tasksViewModel.TaskUsers = taskUsers;

            return PartialView(tasksViewModel);
        }