Esempio n. 1
0
        public void AddTest_AddNull_ThrowException()
        {
            var message = "AddTest异常";

            _dbMock.Setup(db => db.Tests.Add(null)).Throws(new Exception(message));
            var ext = Assert.Throws <Exception>(() => _testRepository.AddTest(null));

            Assert.Contains(message, ext.Message);
        }
Esempio n. 2
0
 public void AddTest(Test test)
 {
     if (test != null)
     {
         repository.AddTest(test);
     }
 }
Esempio n. 3
0
        public IActionResult CreateTest(CreateTestDTO newTest)
        {
            _logger.LogInformation("GET Test/CreateTest");
            User user = null;

            if (Get("user") != null)
            {
                Guid id = Guid.Parse(Get("user"));
                user = _userRepo.GetUser(id);
            }
            if (user == null || user.Role != "Teacher")
            {
                ViewData["LoggedIn"] = "false";
                return(RedirectToAction("Error"));
            }

            if (newTest.Name != "")
            {
                var teacher = _userRepo.GetUser(newTest.TeacherId);
                var test    = new Test(Guid.NewGuid(), newTest.Name, teacher);
                test.Tasks = new List <Task>();

                _testRepo.AddTest(test);
                return(RedirectToAction("ManageTasks", new { testId = test.Id }));
            }
            return(RedirectToAction("Error"));
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([FromBody] Test test)
        {
            var addedTest = await _serviceTest.AddTest(test);

            if (addedTest != null)
            {
                return(Ok(new { success = true, test = addedTest }));
            }
            return(Json(new { success = false }));
        }
Esempio n. 5
0
        public IActionResult AddTest(Test added)
        {
            if (ModelState.IsValid && added != null)
            {
                if (repository.AddTest(added))
                {
                    return(Ok());
                }
            }

            return(BadRequest());
        }
Esempio n. 6
0
        public async Task <ActionResult> CreateTest(DoctorTestViewModel vm, IFormCollection collection)
        {
            var pat = new PatientTest
            {
                TestId       = vm.TestId,
                TestName     = vm.TestName,
                DepartmentId = vm.DepartmentId,
                //Department = vm.deptL
            };

            try
            {
                _testRepository.AddTest(pat);
                await _testRepository.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View(pat));
            }
        }
Esempio n. 7
0
        public int AddTestObject(TestModelDto test)
        {
            int testId = -1;

            try
            {
                int      questionID;
                int      answerID;
                Test     testObj     = null;
                Question questionObj = null;
                Answer   answerObj   = null;

                using (var conn = new SqlConnection(base.GetConnectionString()))
                {
                    conn.Open();
                    testObj = mapper.Map <TestModelDto, Test>(test);
                    testId  = testRepo.AddTest(testObj, conn);

                    if (test.Questions != null)
                    {
                        foreach (var question in test.Questions)
                        {
                            questionObj        = mapper.Map <QuestionModelDto, Question>(question.Question);
                            questionObj.TestID = testId;
                            questionID         = questionRepo.AddQuestion(questionObj, conn);
                            if (question.Answers != null)
                            {
                                foreach (var answer in question.Answers)
                                {
                                    answerObj = mapper.Map <AnswerModelDto, Answer>(answer);
                                    answerID  = answerRepo.AddAnswer(answerObj, conn);
                                    questionAnswerRepo.AddOrUpdateQuestionAnswer(questionID, answerID, answer.Correct, conn);
                                }
                            }
                        }
                    }

                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
                }
            }
            catch (Exception e)
            {
                _log.Error("AddTestObject() error. Test: " + test.Naming, e);
            }

            return(testId);
        }
Esempio n. 8
0
        public Visitation AddVisitation(int doctorId, int patientId, string reason, string notes,
                                        string medicationName, string medicationQuantity, string medicationInstructions,
                                        string treatmentPrescribed, string testPrescribed)
        {
            Visitation visitation = _visitationRepository.CreateVisitation(doctorId, patientId, DateTime.Now, reason, notes);

            if (medicationName != null)
            {
                Medication medication = _medicationRepository.AddMedication(visitation.VisitationId, medicationName, medicationQuantity, medicationInstructions);
            }
            if (testPrescribed != null)
            {
                Test test = _testRepository.AddTest(visitation.VisitationId, testPrescribed);
            }
            if (treatmentPrescribed != null)
            {
                Treatment treatment = _treatmentRepository.AddTreatment(visitation.VisitationId, treatmentPrescribed);
            }

            return(visitation);
        }
Esempio n. 9
0
 public void AddTest(TestViewModel model)
 {
     _testRepository.AddTest(model);
     return;
 }
Esempio n. 10
0
 public int AddTest(Test test)
 {
     return(testRepository.AddTest(test));
 }