Esempio n. 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);
        }
Esempio n. 2
0
        public ActionResult Index()
        {
            TestBusiness tobj = new TestBusiness();

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

            TestBusiness.DeleteTest(test);
            return(RedirectToAction("Index"));
        }
Esempio n. 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;
            }
        }
Esempio n. 5
0
        public IActionResult Index()
        {
            var model = new TestViewModel {
                TestList = TestBusiness.GetTestList(Convert.ToInt32(HttpContext.Session.GetInt32("userId")))
            };

            return(View(model));
        }
Esempio n. 6
0
 public PrintReport()
 {
     InitializeComponent();
     test = new TestBusiness();
     this.grideMes.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
     this.grideMes.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
     this.grideMes.AllowUserToAddRows         = false;
 }
Esempio n. 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();
 }
Esempio n. 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));
        }
Esempio n. 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));
     }
 }
Esempio n. 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);
     }
 }
Esempio n. 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);
        }
Esempio n. 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));
        }
Esempio n. 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);
        }
Esempio n. 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;
 }
Esempio n. 15
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"));
        }
Esempio n. 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);
        }
Esempio n. 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();
        }
Esempio n. 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);
        }
Esempio n. 19
0
 public ExampleBusinessTest(TemplateFixture fixture)
 {
     _exampleBusiness = fixture.ServiceProvider.GetService <TestBusiness>();
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="example"></param>
 public TestController(TestBusiness test)
 {
     _test = test;
 }