コード例 #1
0
        public async Task <IActionResult> CreateQuestion(int onlineTestId, int currQuestion)
        {
            var numbers = await this.examsService.FindQuestionsCount(onlineTestId);

            if (currQuestion == numbers)
            {
                return(this.RedirectToAction("StartTest", "Exams", new { onlineTestId }));
            }

            var model = new QuestionCreateInputModel
            {
                OnlineTestId = onlineTestId,
            };

            return(this.View(model));
        }
コード例 #2
0
        public async Task <IActionResult> Create(QuestionCreateInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }
            model.CreatedOn      = DateTime.UtcNow;
            model.AuthorUserName = this.User.FindFirst(ClaimTypes.Name).Value;
            model.AuthorId       = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            QuestionServiceModel serviceModel = model.To <QuestionServiceModel>();

            await this.questionsService.Create(serviceModel);

            return(this.Redirect("/Questions/All"));
        }
コード例 #3
0
        public async Task <IActionResult> CreateQuestion(int onlineTestId, int currQuestion, QuestionCreateInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var imageUri = string.Empty;

            if (input.Image != null)
            {
                imageUri = await this.themesService
                           .UploadFileToCloudinary(input.Image.FileName, input.Image.OpenReadStream());
            }

            var answerType = input.Type.ToString("g");

            currQuestion++;

            if (answerType == "RadioButtons")
            {
                var questionId = await this.examsService.CreateQuestionAsync(onlineTestId, input.Condition, imageUri);

                var numberOfAnswers = input.NumberOfAnswers;
                return(this.RedirectToAction("CreateAnswers", "Exams", new { onlineTestId, questionId, numberOfAnswers, currQuestion }));
            }
            else
            {
                await this.examsService.CreateQuestionWithAnswerAsync(onlineTestId, input.Condition, imageUri, input.Type);

                return(this.RedirectToAction("CreateQuestion", "Exams", new { onlineTestId, currQuestion }));
            }
        }