Exemplo n.º 1
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Question question = db.Questions.Find(id);

            if (question == null)
            {
                return(HttpNotFound());
            }

            CompositeQuestion qquestion = new CompositeQuestion();

            qquestion.Question = question;
            Course course = db.Courses.FirstOrDefault(m => m.id == question.CourseId);

            qquestion.Course = course;
            Project project = db.Projects.FirstOrDefault(p => p.id == course.ProjectId);

            qquestion.Project = project;

            return(View(qquestion));
        }
Exemplo n.º 2
0
        // GET: Questions
        public ActionResult Index(string ProjectId, string CourseId, string QuestionDesc, int?page)
        {
            //初始化项目名称列表
            List <SelectListItem> projectList = new List <SelectListItem>();
            //根据用户身份做判断
            List <Project> pList = new List <Project>();

            if (UserLogin.userroles.Contains("M"))
            {
                int userid = Convert.ToInt32(UserLogin.userid);
                var user   = db.Users.Where(x => x.id == userid).FirstOrDefault();
                var pros   = from Projects in db.Projects
                             where Projects.ManagerId == user.PersonId
                             select Projects;
                pList = pros.ToList();
            }
            else
            {
                pList = db.Projects.ToList();
            }

            foreach (var item in pList)
            {
                SelectListItem listItem = new SelectListItem();
                listItem.Text  = item.ProjectName;
                listItem.Value = item.id.ToString();
                projectList.Add(listItem);
            }
            ViewData["ProjectList"] = projectList;
            if (String.IsNullOrEmpty(ProjectId))
            {
                List <SelectListItem> courseList = new List <SelectListItem>();
                ViewData["CouserList"] = courseList;
            }
            else
            {
                BindCourse(ProjectId);
            }

            //List<Question> questionList = db.Questions.OrderByDescending(c => c.CourseId).ThenBy(c => c.QuestionNum).ToList();
            //根据用户身份做判断
            List <Question> questionList = new List <Question>();

            if (UserLogin.userroles.Contains("M"))
            {
                int userid    = Convert.ToInt32(UserLogin.userid);
                var user      = db.Users.Where(x => x.id == userid).FirstOrDefault();
                var questions = from Questions in db.Questions
                                join Courses in db.Courses on Questions.CourseId equals Courses.id
                                join Projects in db.Projects on Courses.ProjectId equals Projects.id
                                where Projects.ManagerId == user.PersonId
                                select Questions;
                questionList = questions.OrderBy(c => c.QuestionNum).ToList();
                //questionList = questions.ToList();
            }
            else
            {
                //questionList = db.Questions.OrderByDescending(c => c.CourseId).ThenBy(c => c.QuestionNum).ToList();
                questionList = db.Questions.OrderByDescending(c => c.id).ToList();
            }

            List <CompositeQuestion> qquestionList = new List <CompositeQuestion>();

            foreach (var question in questionList)
            {
                CompositeQuestion qquestion = new CompositeQuestion();
                qquestion.Question = question;
                //与课程表关联
                Course course = db.Courses.FirstOrDefault(m => m.id == question.CourseId);
                qquestion.Course = course;

                //通过课程与项目表关联
                Project project = db.Projects.FirstOrDefault(p => p.id == course.ProjectId);
                qquestion.Project = project;

                qquestionList.Add(qquestion);
            }


            //第几页
            int pageNumbers = page ?? 1;
            //每页显示多少条
            int pageSizes = int.Parse(ConfigurationManager.AppSettings["pageSize"]);

            //筛选条件
            if (!String.IsNullOrEmpty(ProjectId) && ProjectId != "所有项目")
            {
                qquestionList = qquestionList.Where(x => x.Course.ProjectId.Equals(Convert.ToInt32(ProjectId))).ToList();
            }
            if (!String.IsNullOrEmpty(CourseId) && CourseId != "所有课程")
            {
                qquestionList = qquestionList.Where(x => x.Course.id.Equals(Convert.ToInt32(CourseId))).ToList();
            }

            if (!String.IsNullOrEmpty(QuestionDesc))
            {
                qquestionList = qquestionList.Where(x => x.Question.QuestionDesc.Contains(QuestionDesc)).ToList();
            }

            //通过ToPagedList扩展方法进行分页
            IPagedList <CompositeQuestion> pagedList = qquestionList.ToPagedList(pageNumbers, pageSizes);

            //将分页处理后的列表传给View
            this.ViewData["ProjectId"]    = ProjectId;
            this.ViewData["CourseId"]     = CourseId;
            this.ViewData["QuestionDesc"] = QuestionDesc;

            return(View(pagedList));

            //return View(db.Questions.ToList());
        }