Beispiel #1
0
        public TestBusiness GetTestById(int testId)
        {
            Repo = new TestRepository();

            Test test = null;

            try
            {
                test = Repo.GetTest(testId);
            }
            catch (NullReferenceException ex)
            {
                throw;
            }
            catch (InvalidOperationException ex)
            {
                //TODO
            }
            catch (Exception ex)
            {
                //TODO
            }

            TestBusiness testBusiness = TestMapper.MapDalToBiz(test);

            return(testBusiness);
        }
Beispiel #2
0
        public ActionResult Index()
        {
            TestBusiness tobj = new TestBusiness();

            tobj.InitializeDB();
            return(View());
        }
Beispiel #3
0
        public IActionResult DeleteTest(int id)
        {
            var test = TestBusiness.GetTest(id);

            TestBusiness.DeleteTest(test);
            return(RedirectToAction("Index"));
        }
Beispiel #4
0
        public void TestMethodSaveChangesDB_ERR()
        {
            TestBusiness test = new TestBusiness()
            {
                Date   = DateTime.Now,
                UserId = 1
            };
            QuestionBusiness question = new QuestionBusiness()
            {
                TestId = 1,
            };
            AnswerBusiness answer = new AnswerBusiness()
            {
                IsCorrect  = true,
                QuestionId = 1,
                Score      = 10,
            };

            TestService testService = new TestService();

            try
            {
                question.Answers.Add(answer);
                test.Questions.Add(question);

                testService.AddNewTest(test);
            }
            catch (Exception ex)
            {
                int g = 0;
            }
        }
Beispiel #5
0
        public IActionResult Index()
        {
            var model = new TestViewModel {
                TestList = TestBusiness.GetTestList(Convert.ToInt32(HttpContext.Session.GetInt32("userId")))
            };

            return(View(model));
        }
Beispiel #6
0
 public PrintReport()
 {
     InitializeComponent();
     test = new TestBusiness();
     this.grideMes.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
     this.grideMes.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
     this.grideMes.AllowUserToAddRows         = false;
 }
Beispiel #7
0
 public TestDto(TestBusiness test)
 {
     Id                 = test.Id;
     URL                = test.URL;
     Date               = test.Date;
     UserId             = test.UserId;
     Questions          = test.Questions?.Select(q => new QuestionDto(q)).ToList();
     AdministratedTests = test.AdministratedTests?.Select(t => new AdministratedTestDto(t)).ToList();
 }
Beispiel #8
0
        public IActionResult SolveTest(int id)
        {
            var             test      = TestBusiness.GetTest(id);
            List <Question> questions = QuestionBusiness.GetTestQuestion(id);
            var             model     = new TestViewModel {
                QuestionList = questions, Test = test
            };

            return(View(model));
        }
Beispiel #9
0
 public void AddNewTest(TestBusiness test)
 {
     using (TestRepository _repo = new TestRepository())
     {
         if (string.IsNullOrWhiteSpace(test.URL))
         {
             throw new Exception("Test not saved");
         }
         _repo.SaveTest(TestMapper.MapBizToDal(test));
     }
 }
Beispiel #10
0
 public void UpdateTest(TestBusiness test)
 {
     using (TestRepository _repo = new TestRepository())
     {
         if (string.IsNullOrWhiteSpace(test.URL))
         {
             throw new Exception("Test not saved");
         }
         _repo.UpdateTest(test);
     }
 }
Beispiel #11
0
        private TestBusiness MapDalToBizLigth2(TestBusiness test)
        {
            var returned = new TestBusiness
            {
                Id     = test.Id,
                URL    = test.URL,
                Date   = test.Date,
                UserId = test.UserId,
            };

            return(returned);
        }
Beispiel #12
0
        public ActionResult EditQuestion_Get(QuestionDto question)
        {
            TestBusiness questionRelatedTest = _service.GetTestById(question.TestId);

            QuestionDto questionToEdit = new QuestionDto(questionRelatedTest.Questions.FirstOrDefault(q => q.Id == question.Id));

            questionToEdit.CorrectAnswerScore = question.CorrectAnswerScore;

            TestModel questionToUpdate = new TestModel(questionToEdit);

            return(View(questionToUpdate));
        }
Beispiel #13
0
        public static TestBusiness MapDalToBizLigth(Test test)
        {
            var returned = new TestBusiness
            {
                Id        = test.Id,
                URL       = test.URL,
                Date      = test.Date,
                UserId    = test.UserId,
                Questions = test.Questions.Select(QuestionMapper.MapDalToBiz).ToList()
            };

            return(returned);
        }
Beispiel #14
0
 public RecordTestInfomation(string userAcount)
 {
     this.user = userAcount;
     InitializeComponent();
     test                  = new TestBusiness();
     test.Name             = user;
     this.txtCode.KeyDown += new KeyEventHandler(txtCode_KeyDown);
     for (int i = 0; i < control.Length; i++)
     {
         cmbControl.Items.Add(control[i]);
     }
     cmbControl.SelectedIndex = 0;
 }
        public IActionResult Index(HomeViewModel model)
        {
            string key  = Guid.NewGuid().ToString();
            Test   test = new Test {
                title = model.title, content = model.content, userId = Convert.ToInt32(HttpContext.Session.GetInt32("userId")), key = key, createdDate = DateTime.Now
            };

            TestBusiness.AddTest(test);
            Test currentTest = TestBusiness.GetTest(key);

            QuestionBusiness.SaveQuestions(model.Questions, currentTest);
            return(RedirectToAction("Index", "Test"));
        }
Beispiel #16
0
        public static Test MapBizToDal(TestBusiness test)
        {
            var returned = new Test
            {
                Id     = test.Id,
                URL    = test.URL,
                Date   = test.Date,
                UserId = test.UserId,
                //AdministratedTests = test.AdministratedTests.Select(AdministratedTestMapper.MapDomainToDao).ToList(),
                Questions = test.Questions.Select(QuestionMapper.MapBizToDal).ToList(),
            };

            return(returned);
        }
Beispiel #17
0
        public void UpdateTest(TestBusiness test)
        {
            if (test == null)
            {
                throw new NullReferenceException("No test to update");
            }

            Test mappedTest = TestMapper.MapBizToDal(test);

            Test testToUpdate = _ctx.Tests.FirstOrDefault(t => t.Id == test.Id);

            testToUpdate.URL                = mappedTest.URL;
            testToUpdate.User               = mappedTest.User;
            testToUpdate.Date               = mappedTest.Date;
            testToUpdate.UserId             = mappedTest.UserId;
            testToUpdate.AdministratedTests = mappedTest.AdministratedTests;
            testToUpdate.Questions          = mappedTest.Questions;

            _ctx.SaveChanges();
        }
Beispiel #18
0
        public AdministratedTestBusiness AdministratedTest_Builder(TestBusiness test, string subject)
        {
            var newAdTest = new AdministratedTestBusiness();

            newAdTest.Date                   = DateTime.Today;
            newAdTest.URL                    = test.URL;
            newAdTest.TestId                 = test.Id;
            newAdTest.TestSubject            = subject;
            newAdTest.AdministratedQuestions = new List <AdministratedQuestionBusiness>();
            foreach (var q in test.Questions)
            {
                newAdTest.AdministratedQuestions.Add(new AdministratedQuestionBusiness()
                {
                    Text = q.Text,
                    AdministratedTestId  = q.TestId,
                    AdministratedAnswers = q.Answers.Select(a => new AdministratedAnswerBusiness()
                    {
                        Text = a.Text, Score = a.Score, AdministratedQuestionId = a.QuestionId, isCorrect = a.IsCorrect, isSelected = false
                    }).ToList()
                });
            }

            return(newAdTest);
        }
Beispiel #19
0
 public ExampleBusinessTest(TemplateFixture fixture)
 {
     _exampleBusiness = fixture.ServiceProvider.GetService <TestBusiness>();
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="example"></param>
 public TestController(TestBusiness test)
 {
     _test = test;
 }