Esempio n. 1
0
        private void ReadCurrentQuestion()
        {
            Question currentQuestion = new Question();

            currentQuestion.Id          = _question.Id;
            currentQuestion.SubjectName = (string)lbChoiceValExpSubject.Content;
            currentQuestion.SectionName = lbChoiceValExpSection.Content.ToString();
            currentQuestion.TestName    = lbChoiceValExpTest.Content.ToString();

            currentQuestion.QuestionText   = tbQuestionText.Text;
            currentQuestion.QuestionRating = tbQuestionRating.Text;

            var textBoxes  = gcQuestionEdit.Children.OfType <TextBox>().ToList();
            var checkBoxes = gcQuestionEdit.Children.OfType <CheckBox>().ToList();

            for (int i = 0; i < textBoxes.Count; i++)
            {
                if (!string.IsNullOrEmpty(textBoxes[i].Text))
                {
                    var currentAnswerVariant = new AnswerVariant();
                    currentAnswerVariant.Text    = textBoxes[i].Text;
                    currentAnswerVariant.IsRight = (bool)checkBoxes[i].IsChecked;
                    currentQuestion.answerVariant.Add(currentAnswerVariant);
                }
            }
            _question = currentQuestion;
        }
Esempio n. 2
0
        public ActionResult DeleteConfirmed(int id)
        {
            AnswerVariant answervariant = db.AnswerVariants.Find(id);

            db.AnswerVariants.Remove(answervariant);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
 public ActionResult Edit(AnswerVariant answervariant)
 {
     if (ModelState.IsValid)
     {
         db.Entry(answervariant).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(answervariant));
 }
Esempio n. 4
0
        //
        // GET: /A/Edit/5

        public ActionResult Edit(int id = 0)
        {
            AnswerVariant answervariant = db.AnswerVariants.Find(id);

            if (answervariant == null)
            {
                return(HttpNotFound());
            }
            return(View(answervariant));
        }
Esempio n. 5
0
        public ActionResult Create(AnswerVariant answervariant)
        {
            if (ModelState.IsValid)
            {
                db.AnswerVariants.Add(answervariant);
                db.SaveChanges();
                return(RedirectToRoute(new { controller = "A", action = "Create", id = answervariant.QuestionId }));
            }

            return(RedirectToRoute("Error"));
        }
Esempio n. 6
0
        public ActionResult Create(FormCollection values)
        {
            var survey = new SurveyCreate();

            TryUpdateModel(survey);

            try
            {
                Question newQuestion = new Question();
                newQuestion.Text = survey.QuestionText;

                db.Questions.Add(newQuestion);
                db.SaveChanges();


                //костыли
                int newQestId = db.Questions.Single(q => q.Text == survey.QuestionText).QuestionId;

                AnswerVariant newAW = new AnswerVariant {
                    QuestionId = newQestId, Text = survey.AnsverVariant1
                };
                db.AnswerVariants.Add(newAW); db.SaveChanges();
                newAW.Text = survey.AnsverVariant2;
                db.AnswerVariants.Add(newAW); db.SaveChanges();


                if (!String.IsNullOrEmpty(survey.AnsverVariant3) &&
                    !String.IsNullOrWhiteSpace(survey.AnsverVariant3))
                {
                    newAW.Text = survey.AnsverVariant3;
                    db.AnswerVariants.Add(newAW); db.SaveChanges();
                }

                if (!String.IsNullOrEmpty(survey.AnsverVariant4) &&
                    !String.IsNullOrWhiteSpace(survey.AnsverVariant4))
                {
                    newAW.Text = survey.AnsverVariant4;
                    db.AnswerVariants.Add(newAW); db.SaveChanges();
                }

                if (!String.IsNullOrEmpty(survey.AnsverVariant5) &&
                    !String.IsNullOrWhiteSpace(survey.AnsverVariant5))
                {
                    newAW.Text = survey.AnsverVariant5;
                    db.AnswerVariants.Add(newAW); db.SaveChanges();
                }

                if (!String.IsNullOrEmpty(survey.AnsverVariant6) &&
                    !String.IsNullOrWhiteSpace(survey.AnsverVariant6))
                {
                    newAW.Text = survey.AnsverVariant6;
                    db.AnswerVariants.Add(newAW); db.SaveChanges();
                }

                if (!String.IsNullOrEmpty(survey.AnsverVariant7) &&
                    !String.IsNullOrWhiteSpace(survey.AnsverVariant7))
                {
                    newAW.Text = survey.AnsverVariant7;
                    db.AnswerVariants.Add(newAW); db.SaveChanges();
                }

                if (!String.IsNullOrEmpty(survey.AnsverVariant8) &&
                    !String.IsNullOrWhiteSpace(survey.AnsverVariant8))
                {
                    newAW.Text = survey.AnsverVariant8;
                    db.AnswerVariants.Add(newAW); db.SaveChanges();
                }

                if (!String.IsNullOrEmpty(survey.AnsverVariant9) &&
                    !String.IsNullOrWhiteSpace(survey.AnsverVariant9))
                {
                    newAW.Text = survey.AnsverVariant9;
                    db.AnswerVariants.Add(newAW); db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View(survey));
            }
        }
Esempio n. 7
0
        public static void FillDatabase(AppDbContext dbContext, UserManager <AppUser> userManager)
        {
            var adminUser = new AdminUser()
            {
                AdminData = "SomeAdminData",
                UserName  = "******",
                Email     = "[email protected]"
            };

            var result = userManager.CreateAsync(adminUser, "pass3").Result;

            if (!result.Succeeded)
            {
                throw new Exception("can't create admin");
            }


            var teacher = new TeacherUser()
            {
                FullName = "First Teacher",
                Email    = "[email protected]",
                UserName = "******"
            };

            if (!userManager.CreateAsync(teacher, "pass3").Result.Succeeded)
            {
                throw new Exception("can't create teacher");
            }

            var group = new Group()
            {
                Teacher = teacher,
                Name    = "First Group"
            };

            dbContext.Groups.Add(group);

            dbContext.SaveChanges();

            var test = new Test()
            {
                TimeInSeconds = 3600,
                Name          = "test1",
                Group         = group,
                Questions     = new List <Question>()
                {
                    new OneChoiceQuestion()
                    {
                        Number         = 0,
                        Score          = 2,
                        Text           = "q1 ?",
                        AnswerVariants = new AnswerVariant[]
                        {
                            new TextAnswerVariant()
                            {
                                Text = "answ1"
                            },
                            new ImageAnswerVariant()
                            {
                                ImageUrl = "url1"
                            }
                        },
                        RightAnswerNum = 1
                    },
                    new MultiChoiceQuestion()
                    {
                        Number         = 1,
                        Score          = 2,
                        Text           = "q2 ?",
                        AnswerVariants = new AnswerVariant[]
                        {
                            new TextAnswerVariant()
                            {
                                Text = "answ2"
                            },
                            new ImageAnswerVariant()
                            {
                                ImageUrl = "url2"
                            }
                        },
                        RightAnswersNums = new[] { 0, 1 },
                    },
                    new TwoColumnsQuestion()
                    {
                        Number     = 2,
                        Score      = 2,
                        Text       = "q3 ?",
                        LeftColumn = new AnswerVariant[]
                        {
                            new TextAnswerVariant()
                            {
                                Text = "left1"
                            },
                            new ImageAnswerVariant()
                            {
                                ImageUrl = "url_left_2"
                            }
                        },
                        RightColumn = new AnswerVariant[]
                        {
                            new TextAnswerVariant()
                            {
                                Text = "right1"
                            },
                            new ImageAnswerVariant()
                            {
                                ImageUrl = "url_right_2"
                            }
                        },
                        Connections = new (int, int)[]