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);
        }