Ejemplo n.º 1
0
        public async Task <IActionResult> CreateQuestion(QuestionRequestModel model)
        {
            var userId = User.Claims.First(u => u.Type.Equals("sub")).Value;

            var newQuestion = await _questionManager.CreateQuestionAsync(model, userId);

            var response = new ResponseModel <QuestionResponseModel>(newQuestion, true, "Question created successfully");

            return(Ok(response));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CreateQuestion(QuestionModel model)
        {
            if (ModelState.IsValid && await _testManager.IsTestExistsAsync(model.TestId))
            {
                List <int> stages = (await _testManager.GetTestStagesAsync(model.TestId)).ToList();

                if (model.Stage == 0)
                {
                    ViewData["Stage"] = model.Stage;
                    ModelState.AddModelError("", "Invalid Stage");

                    return(View(model));
                }

                if (stages.Count > 0)
                {
                    if (stages[stages.Count - 1] + 2 <= model.Stage)
                    {
                        ViewData["Stage"] = model.Stage;
                        ModelState.AddModelError("", "Invalid Stage");

                        return(View(model));
                    }
                }

                IFormFile image = model.Image;

                if (image != null)
                {
                    string imageFullName = Path.Combine(WebExtensions.ImagesFolderFullName,
                                                        Guid.NewGuid() + Path.GetFileName(image.FileName));
                    image.CopyTo(new FileStream(imageFullName, FileMode.Create));
                    model.ImageFullName = imageFullName;
                }

                var domainQuestion = _mapper.Map <DomainQuestion>(model);

                await _questionManager.CreateQuestionAsync(domainQuestion);

                DomainTest test = await _testManager.GetTestByIdAsync(model.TestId);

                return(RedirectToAction("EditTest", "Test", new { @TopicId = test.TopicId, @TestId = model.TestId }));
            }

            ModelState.AddModelError("", "Invalid Question information");

            return(View(model));
        }
Ejemplo n.º 3
0
        public async Task <QuestionDto> CreateQuestion(QuestionDto question)
        {
            var newQuestion = await _questionManager.CreateQuestionAsync(question);

            return(newQuestion);
        }
Ejemplo n.º 4
0
 public async Task <int> CreateQuestion(QuestionInputDto input)
 {
     return(await _questionManager.CreateQuestionAsync(input.QuestionText, input.AllowMultipleAnswers));
 }
Ejemplo n.º 5
0
 public async Task Post(QuestionDto questionDto)
 {
     await _questionManager.CreateQuestionAsync(questionDto); //TODO: return an empty 201
 }