public OverviewModel ProjectOverview(int Id) { OverviewModel model; int userId = int.Parse(User.Identity.GetProjectUserId()); var managerTask = new TaskManager(); var managerProject = new ProjectUserManager(); var tasks = managerTask.GetTasksForProject(Id); int tasksDone = tasks.Where(t => t.State == managerTask.GetDoneStateId()).Count(); int tasksActive = tasks.Where(t => t.State == managerTask.GetActiveStateId()).Count(); int tasksUnassigned = managerTask.GetUnassignedTasks(Id).Count(); double workHours = managerTask.GetAllWorkTimeForProject(Id) .Sum(w => w.EndTime.Subtract(w.StartTime).TotalSeconds); var users = managerProject.GetUsersForProject(Id); List<string> devs = new List<string>(); foreach (var u in users) { devs.Add(u.UserName); } var project = managerProject.GetProject(Id); var projectLeaderName = managerProject.GetProjectLeader(Id).UserName; model = new OverviewModel( project.Id, project.Name, project.Description, project.Deadline, devs, tasksDone, tasksActive, tasksUnassigned, (int)(workHours / 3600), projectLeaderName); return model; }
private TaskDetailsModel CreateTaskDetailsModel(int userId, int taskId) { var manager = new TaskManager(); var project = manager.GetProjectForTask(taskId); ViewData["isLeader"] = new ProjectUserManager().IsLeader(userId, project.Id); var task = manager.GetTask(taskId); var stateName = manager.GetTaskStateName(taskId); var users = manager.GetUsersForTask(taskId); var workTimes = manager.GetAllWorkTimeForTask(taskId); var comments = manager.GetComments(taskId); var canComment = task.State == manager.GetActiveStateId(); var addableDevelopers = manager.GetAddableOrRemovableDevelopers( taskId, project.Id, addable: true); var removableDevelopers = manager.GetAddableOrRemovableDevelopers( taskId, project.Id, addable: false); var unacceptedDevelopers = manager.GetUnacceptedDevelopers(taskId); var unacceptedTaskStateChanges = manager.GetUnacceptedTaskStateChanges(taskId); var acceptedTaskStateChanges = manager.GetAcceptedTaskStateChanges(taskId); int deletedId = manager.GetDeletedStateId(); ViewData["deletedId"] = deletedId; int doneId = manager.GetDoneStateId(); ViewData["doneId"] = doneId; int activeId = manager.GetActiveStateId(); ViewData["activeId"] = activeId; int newId = manager.GetNewStateId(); ViewData["newId"] = newId; ViewData["isUserOnTask"] = users.Any(u => u.Id == userId); ViewData["isUserApplyUnaccepted"] = unacceptedDevelopers.Any(u => u.Id == userId); Boolean maxDevelopers = task.MaxDevelopers == null ? false : task.MaxDevelopers <= users.Count; ViewData["userHasWorktime"] = workTimes.Any(w => w.ProjectUserId == userId); List<string> devs = new List<string>(); foreach (var u in users) { devs.Add(u.UserName); } List<CommentViewModel> commentViewModels = new List<CommentViewModel>(); foreach (var comment in comments) { var commentingUser = new ProjectUserManager().GetUser(comment.ProjectUserId); commentViewModels.Add( new CommentViewModel(comment.Content, comment.Timestamp, commentingUser.UserName.Trim())); } Dictionary<string, int> userHours = new Dictionary<string, int>(); foreach (var d in devs) { userHours.Add(d, 0); } foreach (var workTime in workTimes) { var userName = users.First(u => u.Id == workTime.ProjectUserId).UserName; int elapsed = (int)(workTime.EndTime.Subtract(workTime.StartTime).TotalSeconds / 3600); int currentHours = userHours[userName]; userHours[userName] = currentHours + elapsed; } bool projectDone = new ProjectUserManager().IsDone(task.ProjectId); return new TaskDetailsModel(task, stateName, devs, userHours, commentViewModels, canComment, addableDevelopers, removableDevelopers, unacceptedDevelopers, unacceptedTaskStateChanges, acceptedTaskStateChanges, projectDone, maxDevelopers); }
private PartialViewResult ShowOverview(int projectId) { OverviewModel model; int userId = int.Parse(User.Identity.GetProjectUserId()); var managerTask = new TaskManager(); var managerProject = new ProjectUserManager(); var tasks = managerTask.GetTasksForProject(projectId); ViewData["isLeader"] = managerProject.IsLeader(userId, projectId); int tasksDone = tasks.Where(t => t.State == managerTask.GetDoneStateId()).Count(); int tasksActive = tasks.Where(t => t.State == managerTask.GetActiveStateId()).Count(); int tasksUnassigned = managerTask.GetUnassignedTasks(projectId).Count(); double workHours = managerTask.GetAllWorkTimeForProject(projectId) .Sum(w => w.EndTime.Subtract(w.StartTime).TotalSeconds); var users = managerProject.GetUsersForProject(projectId); List<string> devs = new List<string>(); foreach (var u in users) { devs.Add(u.UserName); } var project = managerProject.GetProject(projectId); var projectLeaderName = managerProject.GetProjectLeader(projectId).UserName; model = new OverviewModel( project, devs, tasksDone, tasksActive, tasksUnassigned, (int)(workHours / 3600), projectLeaderName); return PartialView("_Overview", model); }