コード例 #1
0
        // GET: Test/Details/{Guid}
        public ActionResult Details(Guid id)
        {
            if (id == Guid.Empty)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            TestGridRow testGridRow = testServices.GetTest(id);

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

            return(View(testGridRow));
        }
コード例 #2
0
        public TestGridRow GetTest(Guid Id)
        {
            var test = new TestGridRow();

            // Get the test
            try
            {
                var testQuery = from tests in dbContext.Tests
                                join examiners in dbContext.Examiners on tests.LastEditedBy equals examiners.Id
                                where tests.Id == Id
                                select new TestGridRow
                {
                    Id        = tests.Id,
                    ShortName = tests.ShortName,
                    Name      = tests.Name,
                    HandlerSignaturePrompt = tests.HandlerSignaturePrompt,
                    LastEditedBy           = examiners.FirstName + " " + examiners.LastName,
                    LastEditedDate         = tests.LastEditedDate
                };
                test = testQuery.FirstOrDefault() ?? new TestGridRow();

                // Get the sections
                var sectionsList  = new List <SectionGridRow>();
                var sectionsQuery = from sections in dbContext.Sections
                                    join examiners in dbContext.Examiners on sections.LastEditedBy equals examiners.Id
                                    where sections.Test == Id
                                    orderby sections.SectionNumber ascending
                                    select new SectionGridRow
                {
                    Id             = sections.Id,
                    SectionNumber  = sections.SectionNumber,
                    Title          = sections.Title,
                    Description    = sections.Description,
                    LastEditedBy   = examiners.FirstName + " " + examiners.LastName,
                    LastEditedDate = sections.LastEditedDate
                };
                sectionsList = sectionsQuery.ToList();


                // Get the questions per section
                foreach (var section in sectionsList)
                {
                    var questionsList  = new List <QuestionGridRow>();
                    var questionsQuery = from questions in dbContext.Questions
                                         join examiners in dbContext.Examiners on questions.LastEditedBy equals examiners.Id
                                         where questions.Section == section.Id
                                         orderby questions.QuestionNumber ascending
                                         select new QuestionGridRow
                    {
                        Id             = questions.Id,
                        Text           = questions.Text,
                        MustPass       = questions.MustPass,
                        QuestionNumber = questions.QuestionNumber,
                        HasYesNo       = questions.HasYesNo,
                        LastEditedBy   = examiners.FirstName + " " + examiners.LastName,
                        LastEditedDate = questions.LastEditedDate
                    };
                    questionsList = questionsQuery.ToList();

                    // Add the questions to the section
                    section.Questions = questionsList;
                }

                // Add the sections to the test
                test.Sections = sectionsList;
            }
            catch (Exception e)
            {
                Debug.WriteLine($"Exception: {e.Message}");
            }
            return(test);
        }