Esempio n. 1
0
 public Question(string name, Models.Project proj, SubjectQuestions squestion)
 {
     Name            = name;
     Project         = proj;
     SubjectQuestion = squestion;
 }
Esempio n. 2
0
 public Question(string name, Models.Project proj, SubjectQuestions squestion)
 {
     Name = name;
     Project = proj;
     SubjectQuestion = squestion;
 }
        public ActionResult MakeQuestionList2()
        {
            var project = from p in _db.Projects
                    orderby p.Id descending
                    select p;

            Project proj = project.First();

            List<string> questions = new List<string>();
            List<SubjectQuestions> squestions = new List<SubjectQuestions>();;
            string[] keys = Request.Form.AllKeys;
            SubjectQuestions currentSubject = null;
            QuestionList qlist = new QuestionList();

            for (int i = 0; i < Request.Form.Count; i++)
            {
                string[] subject = keys[i].Split('-');
                int subjectId = int.Parse(subject[0]);

                string question = Request.Form[i];

                SubjectQuestions squestion = _db.SubjectQuestions.Find(subjectId);
                if (currentSubject == null)
                {
                    currentSubject = new SubjectQuestions(squestion.Subject, squestion.Enabled) { QuestionList = qlist };
                    squestions.Add(currentSubject);
                }
                else if (!squestion.Subject.Equals(currentSubject.Subject))
                {
                    currentSubject = new SubjectQuestions(squestion.Subject, squestion.Enabled) { QuestionList = qlist };
                    squestions.Add(currentSubject);
                }

                Question question1 = new Question(question, proj, currentSubject) { QuestionList = qlist };

                qlist.Questions.Add(question1);
                _db.Questions.Add(question1);
            }
            foreach(SubjectQuestions s in squestions)
            {
                _db.SubjectQuestions.Add(s);
            }

            _db.QuestionLists.Add(qlist);
            proj.Questionlist = qlist;
            _db.SaveChanges();

            return RedirectToAction("Index", "Main");
        }