コード例 #1
0
        public IActionResult Create(CreateExamVM model)
        {
            Wired wired = Wired.GetWireds().FirstOrDefault(f => f.ID == model.wired);

            if (ModelState.IsValid)
            {
                try
                {
                    Test Test = new Test
                    {
                        ReleaseDate = DateTime.Now,
                        title       = wired.title,
                        content     = wired.content
                    };
                    repoTest.Add(Test);
                    for (int i = 0; i < model.Question.Length; i++)
                    {
                        Question question = new Question
                        {
                            name   = model.Question[i],
                            TestID = Test.ID
                        };
                        repoQuestion.Add(question);
                        repoOption.Add(new Option
                        {
                            answer     = model.A[i],
                            pIndex     = 1,
                            QuestionID = question.ID,
                            correct    = model.correct[i] == 1 ? true : false
                        });
                        repoOption.Add(new Option
                        {
                            answer     = model.B[i],
                            pIndex     = 2,
                            QuestionID = question.ID,
                            correct    = model.correct[i] == 2 ? true : false
                        });
                        repoOption.Add(new Option
                        {
                            answer     = model.C[i],
                            pIndex     = 3,
                            QuestionID = question.ID,
                            correct    = model.correct[i] == 3 ? true : false
                        });
                        repoOption.Add(new Option
                        {
                            answer     = model.D[i],
                            pIndex     = 4,
                            QuestionID = question.ID,
                            correct    = model.correct[i] == 4 ? true : false
                        });
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception)
                {
                    return(View(model));
                }
            }
            else
            {
                return(View());
            }
        }
コード例 #2
0
 public IActionResult GetWiredContent(int WiredID)
 {
     return(Content(Wired.GetWireds().FirstOrDefault(f => f.ID == WiredID).content));
 }
コード例 #3
0
        public IActionResult Create()
        {
            List <Wired> wireds = Wired.GetWireds();

            return(View(wireds));
        }