Пример #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 LoadCompletedTasks(string projectId, string username)
        {
            DashboardModel model = new DashboardModel();
            Project        p     = null;

            bool isProjectManager = Authentication.VerifyIfProjectManager(username);

            if (projectId.Equals("_all"))
            {
                List <Task> tasks = new List <Task>();

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

                    DataRow[] drs1 = null;
                    if (isProjectManager)
                    {
                        drs1 = model.GetAllTasks(currProjectId);
                    }
                    else
                    {
                        drs1 = model.GetTasks(username, currProjectId);
                    }

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

                        tasks.Add(new Task {
                            Title         = dr1["title"].ToString(),
                            Priority      = dr1["priority"].ToString(),
                            DueDate       = dueDate,
                            Status        = DateTime.Now < dueDate ? "On time" : "Overdue",
                            ProjectName   = projectTitle,
                            CompletedDate = completionDate,
                        });
                    }
                }
                p = new Project {
                    Tasks = tasks.ToArray()
                };
            }
            else
            {
                int iProjectId = Convert.ToInt32(projectId);

                List <Task> tasks = new List <Task>();
                if (!isProjectManager)
                {
                    p = model.GetProject(username, projectId);
                }
                else
                {
                    p = model.GetProject(username, projectId);

                    DataRow[] drs1 = model.GetAllTasks(iProjectId);

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

                        tasks.Add(new Task {
                            Title         = dr1["title"].ToString(),
                            Priority      = dr1["priority"].ToString(),
                            DueDate       = dueDate,
                            Status        = DateTime.Now < dueDate ? "On time" : "Overdue",
                            ProjectName   = p.Title,
                            CompletedDate = completionDate,
                        });
                    }

                    p.Tasks = tasks.ToArray();
                }
            }


            return(Json(new { success = true, message = p.Tasks }));
        }