コード例 #1
0
        public ActionResult AcceptStateChange(int taskId, int developerId)
        {
            var manager = new TaskManager();

            int userId = int.Parse(User.Identity.GetProjectUserId());
            var projectId = manager.GetProjectForTask(taskId).Id;

            manager.AcceptStateChange(taskId, developerId);

            TempData["DetailsPage"] = "1";
            TempData["overlayId"] = "TaskDetails";
            TempData["TaskDetailsId"] = "" + taskId;
            return Redirect("/Projects/Details/" + projectId);
        }
コード例 #2
0
        public ActionResult AddDeveloper(int taskId)
        {
            var manager = new TaskManager();

            int userId = int.Parse(User.Identity.GetProjectUserId());
            var projectId = manager.GetProjectForTask(taskId).Id;

            if (Request.Form["addUserId"] != null)
            {
                int developerId = int.Parse(Request.Form["addUserId"]);
                manager.AddDeveloperToTask(developerId, taskId, accepted: true);
            }

            TempData["DetailsPage"] = "1";
            TempData["overlayId"] = "TaskDetails";
            TempData["TaskDetailsId"] = "" + taskId;
            return Redirect("/Projects/Details/" + projectId);
        }
コード例 #3
0
        public ActionResult AddWorkTime(int taskId)
        {
            var manager = new TaskManager();

            int userId = int.Parse(User.Identity.GetProjectUserId());
            var projectId = manager.GetProjectForTask(taskId).Id;
            DateTime startTime = DateTime.Now.AddHours(1);
            DateTime endTime = DateTime.Now;
            try
            {
                startTime = DateTime.Parse(Request.Form["startTime"]);
                endTime = DateTime.Parse(Request.Form["endTime"]);
            }
            catch (Exception ex)
            {
                TempData["errorMessage"] = "Wrong date/time format!";
            }

            if (startTime < endTime && startTime.AddMinutes(-5) < DateTime.Now)
            {
                WorktimeData data = new WorktimeData()
                {
                    ProjectUserId = userId,
                    TaskId = taskId,
                    StartTime = startTime,
                    EndTime = endTime
                };

                if (!manager.AddWorkTime(data))
                {
                    TempData["errorMessage"] = "Overlapping work time!";
                }
            }
            else
            {
                TempData["errorMessage"] = "Invalid start or end time!";
            }

            TempData["DetailsPage"] = "1";
            TempData["overlayId"] = "TaskDetails";
            TempData["TaskDetailsId"] = "" + taskId;
            return Redirect("/Projects/Details/" + projectId);
        }
コード例 #4
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);
        }
コード例 #5
0
        public ActionResult RestoreTask(int taskId)
        {
            var manager = new TaskManager();

            int userId = int.Parse(User.Identity.GetProjectUserId());
            var projectId = manager.GetProjectForTask(taskId).Id;
            var reason = Request.Form["restoreReason"];

            manager.RestoreTask(taskId, userId, reason);

            TempData["DetailsPage"] = "1";
            return Redirect("/Projects/Details/" + projectId);
        }
コード例 #6
0
        public ActionResult ReopenTask(int taskId)
        {
            var manager = new TaskManager();

            int userId = int.Parse(User.Identity.GetProjectUserId());
            var projectId = manager.GetProjectForTask(taskId).Id;
            var isLeader = new ProjectUserManager().IsLeader(userId, projectId);
            var reason = Request.Form["reopenReason"];

            manager.UnfinishTask(taskId, userId, reason, isLeader);

            TempData["DetailsPage"] = "1";
            TempData["overlayId"] = "TaskDetails";
            TempData["TaskDetailsId"] = "" + taskId;
            return Redirect("/Projects/Details/" + projectId);
        }
コード例 #7
0
        public ActionResult FinalizeUserApplication(int taskId)
        {
            var manager = new TaskManager();

            int userId = int.Parse(User.Identity.GetProjectUserId());
            var projectId = manager.GetProjectForTask(taskId).Id;

            if (!manager.FinalizeUserApplication(taskId))
            {
                // TODO: error display
            }

            TempData["DetailsPage"] = "1";
            TempData["overlayId"] = "TaskDetails";
            TempData["TaskDetailsId"] = "" + taskId;
            return Redirect("/Projects/Details/" + projectId);
        }
コード例 #8
0
        public ActionResult ApplyDeveloper(int taskId)
        {
            var manager = new TaskManager();

            int userId = int.Parse(User.Identity.GetProjectUserId());
            var projectId = manager.GetProjectForTask(taskId).Id;

            manager.AddDeveloperToTask(userId, taskId, accepted: false);

            TempData["DetailsPage"] = "1";
            TempData["overlayId"] = "TaskDetails";
            TempData["TaskDetailsId"] = "" + taskId;
            return Redirect("/Projects/Details/" + projectId);
        }