Ejemplo n.º 1
0
        private PartialViewResult ShowDevelopers(int projectId)
        {
            List<DeveloperListElement> model = new List<DeveloperListElement>();

            int userId = int.Parse(User.Identity.GetProjectUserId());

            var managerTask = new TaskManager();
            var managerProject = new ProjectUserManager();

            ViewData["projectId"] = projectId;
            ViewData["isLeader"] = managerProject.IsLeader(userId, projectId);
            ViewData["isDone"] = managerProject.GetProject(projectId).Done;

            var tasks = managerTask.GetTasksForProject(projectId);
            var users = managerProject.GetUsersForProject(projectId);

            foreach (var u in users)
            {
                var workHours = managerTask.GetAllWorkTimeForUser(u.Id, projectId)
                    .Sum(w => w.EndTime.Subtract(w.StartTime).TotalSeconds);

                int tasksDone = tasks.Where(t => t.State == managerTask.GetDoneStateId()).Count();
                int tasksAssigned = managerTask.GetAssignedTasks(u.Id, projectId).Count();

                model.Add(new DeveloperListElement(u, (int)(workHours / 3600), tasksDone, tasksAssigned));
            }

            return PartialView("_Developers", model);
        }
        private void BuildUserWorkTimeValues(List<object> xValues, List<object> yValues, DateTime startTime, DateTime endTime,
            int projectId)
        {
            var managerProject = new ProjectUserManager();
            var managerTask = new TaskManager();

            var users = managerProject.GetUsersForProject(projectId);
            foreach (var u in users)
            {
                double seconds = 0.0;

                if (startTime != DateTime.MinValue && endTime != DateTime.MinValue)
                {
                    seconds = managerTask.GetAllWorkTimeForUser(u.Id, projectId)
                        .Where(wt => wt.StartTime >= startTime && wt.EndTime <= endTime)
                        .Sum(w => w.EndTime.Subtract(w.StartTime).TotalSeconds);
                }
                else if (startTime != DateTime.MinValue && endTime == DateTime.MinValue)
                {
                    seconds = managerTask.GetAllWorkTimeForUser(u.Id, projectId)
                        .Where(wt => wt.StartTime >= startTime)
                        .Sum(w => w.EndTime.Subtract(w.StartTime).TotalSeconds);
                }
                else if (startTime == DateTime.MinValue && endTime != DateTime.MinValue)
                {
                    seconds = managerTask.GetAllWorkTimeForUser(u.Id, projectId)
                        .Where(wt => wt.EndTime <= endTime)
                        .Sum(w => w.EndTime.Subtract(w.StartTime).TotalSeconds);
                }
                else
                {
                    seconds = managerTask.GetAllWorkTimeForUser(u.Id, projectId)
                        .Sum(w => w.EndTime.Subtract(w.StartTime).TotalSeconds);
                }

                xValues.Add(u.UserName);
                yValues.Add(((int)seconds / 3600));
            }
        }