Ejemplo n.º 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;
        }
Ejemplo n.º 2
0
        // GET: Add developer dialog
        public ActionResult AddDeveloperDialog(int Id)
        {
            int userId = int.Parse(User.Identity.GetProjectUserId());

            var manager = new ProjectUserManager();
            var addableDevelopers = manager.GetAddableOrRemovableDevelopers(
                Id, userId, addable: true);
            var removableDevelopers = manager.GetAddableOrRemovableDevelopers(
                Id, userId, addable: false);

            return PartialView("_AddDeveloperDialog", new AddDeveloperDialogModel(Id, addableDevelopers, removableDevelopers));
        }
Ejemplo n.º 3
0
        public ActionResult AddDeveloper()
        {
            int userId = int.Parse(User.Identity.GetProjectUserId());
            int projectId = int.Parse(Request.Form["projectId"]);

            if (Request.Form["addUserId"] != null)
            {
                int developerId = int.Parse(Request.Form["addUserId"]);
                TempData["DetailsPage"] = "2";

                var manager = new ProjectUserManager();
                if (manager.IsLeader(userId, projectId))
                {
                    manager.AddDeveloperToProject(developerId, projectId);
                }
            }

            return Redirect("Details/" + projectId);
        }
Ejemplo n.º 4
0
        public IEnumerable<ProjectData> Projects()
        {
            int userId = int.Parse(User.Identity.GetProjectUserId());

            List<ProjectData> res = new List<ProjectData>();
            var projectUserManager = new ProjectUserManager();
            foreach (Project p in projectUserManager.GetProjectsForUser(userId))
            {
                ProjectData data = new ProjectData();
                data.Id = p.Id;
                data.Name = p.Name;
                data.Description = p.Description;
                data.Deadline = p.Deadline;
                data.Done = p.Done;
                res.Add(data);
            }

            return res;
        }
Ejemplo n.º 5
0
        public void AddDeveloperToTask(int userId, int taskId, bool accepted)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                int developerId = new ProjectUserManager().GetDeveloperId();
                var assignments = context.Assignment.Where(
                    a => a.TaskId == taskId && a.ProjectUserId == userId);

                if (assignments.Count() == 0)
                {
                    context.Assignment.Add(new Assignment()
                    {
                        ProjectUserId = userId,
                        TaskId = taskId,
                        Accepted = accepted
                    });

                    context.SaveChanges();
                }
            }
        }
Ejemplo n.º 6
0
        private PartialViewResult ShowTasks(int projectId)
        {
            List<TaskListElement> model = new List<TaskListElement>();

            int userId = int.Parse(User.Identity.GetProjectUserId());
            var manager = new TaskManager();

            int deletedId = manager.GetDeletedStateId();

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

            var tasks = manager.GetTasksForProject(projectId);

            foreach (var t in tasks)
            {
                var name = manager.GetTaskStateName(t.Id);

                var isCommented = manager.IsCommented(t.Id);

                var workHours = manager.GetAllWorkTimeForTask(t.Id)
                    .Sum(w => w.EndTime.Subtract(w.StartTime).TotalSeconds);

                var developers = manager.GetUsersForTask(t.Id);

                List<string> devs = new List<string>();
                foreach (var v in developers)
                {
                    devs.Add(v.UserName);
                }

                TaskListElement element = new TaskListElement(t, name, devs, (int)(workHours / 3600), isCommented);
                model.Add(element);
            }

            return PartialView("_Tasks", model);
        }
Ejemplo n.º 7
0
        private PartialViewResult ShowStatistics(int projectId)
        {
            List<StatisticsListElement> model = new List<StatisticsListElement>();

            var manager = new StatisticsManager();
            int userId = int.Parse(User.Identity.GetProjectUserId());
            ViewData["isLeader"] = new ProjectUserManager().IsLeader(userId, projectId);
            ViewData["projectId"] = projectId;

            var statistics = manager.GetAllStatistics(projectId);

            return PartialView("_Statistics", statistics);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
        // GET: Project details
        public ActionResult Details(int Id)
        {
            int userId = int.Parse(User.Identity.GetProjectUserId());

            var project = new ProjectUserManager().GetProjectsForUser(userId).First(p => p.Id == Id);

            int pageId = 0;
            Object savedValue;
            if (TempData.TryGetValue("DetailsPage", out savedValue)){
                pageId = int.Parse(savedValue as string);
                TempData.Remove("DetailsPage");
            }

            if (TempData.ContainsKey("overlayId")){
                ViewData["overlayId"] = TempData["overlayId"];
                if (TempData["overlayId"].ToString().Contains("TaskDetails"))
                {
                    ViewData["TaskDetailsId"] = TempData["TaskDetailsId"];
                }
            }

            ProjectDetailsViewModel model = new ProjectDetailsViewModel(project, pageId);

            if (TempData.ContainsKey("errorMessage"))
            {
                ViewData["errorMessage"] = TempData["errorMessage"];
            }

            if (TempData.ContainsKey("UnsavedStatistics"))
            {
                ViewData["UnsavedStatistics"] = TempData["UnsavedStatistics"];
            }

            return View(model);
        }
Ejemplo n.º 12
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                int projectUserId = new ProjectUserManager().AddUserAndReturnId(model.UserName);

                var user = new ApplicationUser
                {
                    UserName = model.UserName,
                    Email = model.Email,
                    EmailConfirmed = true,
                    ProjectUserId = projectUserId
                };

                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                     //string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                     //var callbackUrl = Url.Action(
                     //    "ConfirmEmail", "Account",
                     //    new { userId = user.Id, code = code },
                     //    protocol: Request.Url.Scheme);

                     //await UserManager.SendEmailAsync(user.Id,
                     //    "Confirm your account",
                     //    "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Ejemplo n.º 13
0
        public void RemoveDeveloperFromTask(int userId, int taskId)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                int developerId = new ProjectUserManager().GetDeveloperId();
                var assignment = context.Assignment.FirstOrDefault(
                    a => a.TaskId == taskId && a.ProjectUserId == userId);

                if (assignment != null)
                    context.Assignment.Remove(assignment);

                context.SaveChanges();
            }
        }
Ejemplo n.º 14
0
        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));
            }
        }
Ejemplo n.º 15
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));
            }
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
        public ActionResult PostComment(int Id)
        {
            int userId = int.Parse(User.Identity.GetProjectUserId());

            var content = Request.Form["commentContent"];
            if (content == string.Empty)
            {
                return PartialView("_Comment", null);
            }

            DateTime timeStamp = DateTime.Now;
            new CommentManager().AddComment(new CommentData()
            {
                ProjectUserId = userId,
                TaskId = Id,
                Timestamp = timeStamp,
                Content = content
            });

            var userName = new ProjectUserManager().GetUser(userId).UserName.Trim();

            return PartialView("_Comment", new CommentViewModel(content, timeStamp, userName));
        }
Ejemplo n.º 18
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());
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
0
        // GET: Projects
        public ActionResult Index()
        {
            int userId = int.Parse(User.Identity.GetProjectUserId());
            var projectUserManager = new ProjectUserManager();
            var taskManager = new TaskManager();

            var projects = projectUserManager.GetProjectsForUser(userId);
            var projectListElements = new List<ProjectListElement>();

            foreach (var p in projects)
            {
                int devs = projectUserManager.GetUsersForProject(p.Id).Count;
                int tasks = taskManager.GetTasksForProject(p.Id).Count;
                var element = new ProjectListElement(p, devs, tasks);
                projectListElements.Add(element);
            }

            if (TempData.ContainsKey("errorMessage")){
                ViewData["errorMessage"] = TempData["errorMessage"];
            }

            return View(new ProjectsViewModel(projectListElements));
        }