Exemplo n.º 1
0
        public async Task <IActionResult> AddTest([FromBody] TestViewModel formdata)
        {
            try
            {
                if (formdata == null)
                {
                    return(BadRequest(new JsonResult(new { message = "object sent from client is null." })));
                }
                else if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object sent from client."));
                }
                var test     = _mapper.Map <TestDto>(formdata);
                var testData = await _testService.AddTest(test);

                if (testData == Guid.Empty)
                {
                    return(NotFound());
                }
                test.Id = testData;
                var addedTest = _mapper.Map <TestViewModel>(test);
                return(CreatedAtAction(nameof(GetTest), new { id = testData }, addedTest));
            }
            catch (Exception e)
            {
                return(StatusCode(500, $"Something went wrong inside add test action: {e.Message}"));
            }
        }
        public async Task <IActionResult> AddTest([FromBody] EditTestModel addTestModel)
        {
            var addTestDto = mapper.Map <AddTestDto>(addTestModel);
            var addResult  = await testService.AddTest(addTestDto);

            return(responseComposer.ComposeAddTest(addResult));
        }
 public IActionResult Add(int id, TestViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View());
     }
     _testService.AddTest(model);
     return(RedirectToAction("Add", "Test"));
 }
Exemplo n.º 4
0
 public ActionResult Create(TestViewModel test, int?subjectRedirrect)   // [Bind(Include = "TestId,Name,Complexity,Rate,Duration,IsApproved")]
 {
     if (ModelState.IsValid)
     {
         TestDto testDto = _mapper.Map <TestViewModel, TestDto>(test);
         _testService.AddTest(testDto);
         return(RedirectToAction("Details", "Subjects", new { subjectId = test.SubjectId }));
     }
     return(View(test));
 }
        public IHttpActionResult Post([FromBody] TestVM testVM)
        {
            if (testVM == null || !testVM.isWalid())
            {
                return(BadRequest());
            }

            _testService.AddTest(Mapper.Map <TestDTO>(testVM));
            return(Ok());
        }
Exemplo n.º 6
0
        public ActionResult AddTest(Test tst)
        {
            var tstID = _testService.AddTest(tst);

            if (tstID != 0)
            {
                return(Json(new
                {
                    message = "Test save successfully",
                    success = true,
                    model = tstID
                }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new
                {
                    message = "Failed to save test",
                    success = false
                }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 7
0
        public IActionResult CreateTest(TestParamViewModel testModel)
        {
            List <Question> questions = testModel.Test.Question;

            for (int i = 0; i < questions.Count; i++)
            {
                if (questions[i].Answer.Where(p => p.IsCorrect).Count() != 1)
                {
                    ModelState.AddModelError("", $"Правильным должен быть 1 вариант ответа (Вопрос №{i + 1})");
                }
            }

            if (ModelState.IsValid)
            {
                handler.CheckValue(testModel);
                testService.AddTest(testModel.Test);
                TempData["message"] = "Отлично!!! Тест успешно создан";
                return(RedirectToAction(nameof(GetListTests), new { id = testModel.Test.CategoryId }));
            }
            else
            {
                return(View(nameof(BuildAnswers), testModel));
            }
        }
Exemplo n.º 8
0
        public IActionResult PostTests([FromBody] TestRequest request)
        {
            var response = _testService.AddTest(request);

            return(Ok(response));
        }