コード例 #1
0
        public override void UpdateEntity(TextBox[] textBoxName)
        {
            int      qid      = Convert.ToInt32(textBoxName.FirstOrDefault(s => s.ID == "id")?.Text);
            Question question = Context.Get(s => s.Id == qid);

            Easy             easy          = new Easy();
            Classic          classic       = new Classic();
            ClassicAnswer    classicAnswer = new ClassicAnswer();
            IAnswerPresenter answer        = null;

            TextBox[] answerTextBoxs = textBoxName.Where(s => s.ID.ToLower().Contains("answer")).ToArray();
            foreach (TextBox textBox in textBoxName)
            {
                if (!textBox.ID.ToLower().Contains("answer"))
                {
                    if (textBox.ID.ToLower().Contains("points"))
                    {
                        decimal d = Convert.ToDecimal(textBox.Text.Replace(".", ","));
                        question.Points = d;
                    }
                    else if (textBox.ID.ToLower().Contains("question"))
                    {
                        question.MyQuestion = textBox.Text;
                    }
                    else if (textBox.ID.ToLower().Contains("selectdifficulty"))
                    {
                        question.Difficulty = easy.Handle(Convert.ToInt32(textBox.Text));
                    }
                    else if (textBox.ID.ToLower().Contains("selecttype"))
                    {
                        question.Type = classic.Handle(Convert.ToInt32(textBox.Text));
                        answer        = classicAnswer.Handle((int)question.Type);
                    }
                    else if (textBox.ID.ToLower().Contains("selectlesson"))
                    {
                        question.LessonId = Convert.ToInt32(textBox.Text);
                    }
                }
            }
            Context.Update(question);
            if (answerTextBoxs.Length > 0)
            {
                answer?.UpdateAnswer(answerTextBoxs, question.Id);
            }

            ListEntityWithCollapsibleTable();
        }
コード例 #2
0
        public override void AddEntity(TextBox[] textBoxName)
        {
            Easy             easy          = new Easy();
            Classic          classic       = new Classic();
            ClassicAnswer    classicAnswer = new ClassicAnswer();
            Question         question      = new Question();
            IAnswerPresenter answer        = null;

            TextBox[] answerTextBoxs = textBoxName.Where(s => s.ID.ToLower().Contains("answer")).ToArray();
            int       lid            = 0;

            foreach (TextBox textBox in textBoxName)
            {
                if (!textBox.ID.ToLower().Contains("answer"))
                {
                    if (textBox.ID.ToLower().Contains("points"))
                    {
                        decimal d = Convert.ToDecimal(textBox.Text.Replace(".", ","));
                        question.Points = d;
                    }
                    else if (textBox.ID.ToLower().Contains("question"))
                    {
                        question.MyQuestion = textBox.Text;
                    }
                    else if (textBox.ID.ToLower().Contains("selectdifficulty"))
                    {
                        question.Difficulty = easy.Handle(Convert.ToInt32(textBox.Text));
                    }
                    else if (textBox.ID.ToLower().Contains("selecttype"))
                    {
                        question.Type = classic.Handle(Convert.ToInt32(textBox.Text));
                        answer        = classicAnswer.Handle((int)question.Type);
                    }
                    else if (textBox.ID.ToLower().Contains("selectlesson"))
                    {
                        lid = Convert.ToInt32(textBox.Text);
                        question.LessonId = lid;
                    }
                }
            }


            Context.Add(question);
            answer?.AddAnswer(answerTextBoxs, question.Id);
            ListEntityWithCollapsibleTable();
        }