Beispiel #1
0
        public ActionResult UpdateProject(string projectId, string sUser)
        {
            List <Task>    selectedTasks = new List <Task>();
            DashboardModel model         = new DashboardModel();

            DataRow[] drs;

            bool isProjectManager = false;

            if (projectId == "_all")
            {
                isProjectManager = Authentication.VerifyIfProjectManager(sUser);
                Project[] projects = GetAllProjects(sUser, model);
                model.Projects = projects;
                foreach (Project p in projects)
                {
                    foreach (Task t in p.Tasks)
                    {
                        selectedTasks.Add(t);
                    }
                }
            }
            else
            {
                int iProjectId = Convert.ToInt32(projectId);
                model = new DashboardModel();


                isProjectManager = Authentication.VerifyIfProjectManager(sUser);
                if (isProjectManager)
                {
                    drs = model.GetAllTasks(iProjectId);
                }
                else
                {
                    drs = model.GetTasks(sUser, iProjectId);
                }

                string projectName = model.GetProjectName(projectId);

                foreach (DataRow dr in drs)
                {
                    DateTime dueDate        = Convert.ToDateTime(dr["dueDate"]);
                    DateTime completionDate = Convert.ToDateTime(dr["completionDate"]);

                    string completionDateString = completionDate.ToString("MM/dd/yyyy");
                    if (!completionDateString.Equals("01/01/0001") && !completionDateString.Equals("01-01-0001"))
                    {
                        continue;
                    }


                    selectedTasks.Add(new Task {
                        Title         = dr["title"].ToString(),
                        Priority      = dr["priority"].ToString(),
                        DueDate       = dueDate,
                        Status        = DateTime.Now < dueDate ? "On time" : "Overdue",
                        ProjectName   = projectName,
                        CompletedDate = completionDate,
                        Users         = model.GetTaskUsers(Convert.ToInt32(dr["taskId"]))
                    });
                }

                model.Projects = new Project[] {
                    new Project {
                        Tasks = selectedTasks.ToArray()
                    }
                };
            }

            var users = new System.Text.StringBuilder();



            var sb = new System.Text.StringBuilder();

            foreach (Task task in selectedTasks)
            {
                users.Clear();
                users.Append("");
                if (isProjectManager)
                {
                    foreach (User u in task.Users)
                    {
                        if (task.Users.Last() != u)
                        {
                            users.Append($"{u.FirstName} {u.LastName}, ");
                        }
                        else
                        {
                            users.Append($"{u.FirstName} {u.LastName}");
                        }
                    }
                }
                sb.Append($"<tr>" +
                          $"<td>{task.Title}</td>" +
                          $"<td>{task.Priority}</td>" +
                          $"<td>{task.DueDate.ToString("MM/dd/yyyy")}</td>" +
                          $"<td>{task.Status}</td>" +
                          $"<td>{task.ProjectName}</td>" +
                          (isProjectManager ? $"<td>{users.ToString()}</tb>" : "") +
                          $"</tr>");
            }

            return(Json(new { row = sb.ToString() }));
        }