示例#1
0
        private Project[] GetAllProjects(string username, DashboardModel model)
        {
            DataRow[] drs, drs1 = null;
            drs = model.GetProjects(username);


            projects = new Project[drs.Count()];

            int i = 0;

            foreach (DataRow dr in drs)
            {
                int    currProjectId = Int32.Parse(drs[i]["projectId"].ToString());
                string projectTitle  = dr["title"].ToString();

                if (Authentication.VerifyIfProjectManager(username))
                {
                    drs1 = model.GetAllTasks(currProjectId);
                }
                else
                {
                    drs1 = model.GetTasks(username, currProjectId);
                }

                List <Task> currProjectTasks = new List <Task>();

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

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

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

                projects[i++] = new Project {
                    ProjectId = Int32.Parse(dr["projectId"].ToString()),
                    Title     = projectTitle,
                    Tasks     = currProjectTasks.ToArray()
                };
            }

            return(projects);
        }
示例#2
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() }));
        }