コード例 #1
0
        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;
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
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);
        }
コード例 #5
0
        public ActionResult Finish(int Id)
        {
            int userId = int.Parse(User.Identity.GetProjectUserId());

            var project = new ProjectUserManager().GetProject(Id);

            var manager = new TaskManager();
            var tasks = new TaskManager().GetTasksForProject(Id);

            if (tasks.Count == 0 ||
                tasks.All(t => t.State == manager.GetDeletedStateId() || t.State == manager.GetDoneStateId()))
            {
                new ProjectUserManager().FinishProject(Id);
            }
            else
            {
                TempData["errorMessage"] = "Can't finish project, there are still tasks in progress!";
            }

            return Redirect(Request.UrlReferrer.ToString());
        }
コード例 #6
0
        private void BuildTaskDoneWorktimeValues(List<object> xValues, List<object> yValues, DateTime startTime, DateTime endTime,
            int projectId)
        {
            var managerProject = new ProjectUserManager();
            var managerTask = new TaskManager();

            int doneId = managerTask.GetDoneStateId();
            var doneTasks = managerTask.GetTasksForProject(projectId).Where(t => t.State == doneId);
            foreach (var t in doneTasks)
            {
                double seconds = 0.0;

                if (startTime != DateTime.MinValue && endTime != DateTime.MinValue)
                {
                    seconds = managerTask.GetAllWorkTimeForTask(t.Id)
                        .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.GetAllWorkTimeForTask(t.Id)
                        .Where(wt => wt.StartTime >= startTime)
                        .Sum(w => w.EndTime.Subtract(w.StartTime).TotalSeconds);
                }
                else if (startTime == DateTime.MinValue && endTime != DateTime.MinValue)
                {
                    seconds = managerTask.GetAllWorkTimeForTask(t.Id)
                        .Where(wt => wt.EndTime <= endTime)
                        .Sum(w => w.EndTime.Subtract(w.StartTime).TotalSeconds);
                }
                else
                {
                    seconds = managerTask.GetAllWorkTimeForTask(t.Id)
                        .Sum(w => w.EndTime.Subtract(w.StartTime).TotalSeconds);
                }

                xValues.Add(t.Name);
                yValues.Add(((int)seconds / 3600));
            }
        }
コード例 #7
0
        private void BuildNumberOfFinishedTasksValues(List<object> xValues, List<object> yValues, DateTime startTime, DateTime endTime,
            int projectId)
        {
            var managerProject = new ProjectUserManager();
            var managerTask = new TaskManager();

            int count = 0;
            int doneId = managerTask.GetDoneStateId();
            var doneTasks = managerTask.GetTasksForProject(projectId).Where(t => t.State == doneId);
            foreach (var t in doneTasks)
            {
                var dtst = managerTask.GetDoneTaskStateChanges(t.Id);
                if (dtst.Count == 0)    // invalid test data
                    continue;

                var max = dtst.Max(st => st.Timestamp);
                var finalStateChange = dtst.SingleOrDefault(st => st.Timestamp == max);

                if (startTime != DateTime.MinValue && endTime != DateTime.MinValue)
                {
                    if (finalStateChange.Timestamp >= startTime && finalStateChange.Timestamp <= endTime)
                        count++;
                }
                else if (startTime != DateTime.MinValue && endTime == DateTime.MinValue)
                {
                    if (finalStateChange.Timestamp >= startTime)
                        count++;
                }
                else if (startTime == DateTime.MinValue && endTime != DateTime.MinValue)
                {
                    if (finalStateChange.Timestamp <= endTime)
                        count++;
                }
                else
                {
                    count++;
                }
            }

            xValues.Add("Finished Tasks");
            yValues.Add(count);
        }