public async Task <int> AddQuestionAsync(QuestionDTO questionsDTO) { var question = _mapper.Map <Question>(questionsDTO); await _repository.AddQuestionAsync(question); return(question.Id); }
public async Task AddQuestionAsync(AddQuestionDto questionDto) { if (questionDto == null) { throw new InvalidOperationException("Question mustn't be null"); } await _repository.AddQuestionAsync(questionDto); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } await questionRepository.AddQuestionAsync(Question); return(RedirectToPage("/Questions/Edit", new { Question.Id })); }
public async Task <IActionResult> AddQuestion([FromBody] Question question) { try { return(Ok(await questionRepository.AddQuestionAsync(question))); } catch (Exception) { throw; } }
public async Task <string> AddQuestionAsync(ResponseData.Question question) { if (question == null || question.TopicId == null) { throw new ArgumentException("Invalid question or topicId"); } await _questionRepository.AddQuestionAsync(new DataEntity.Question { TopicId = question.TopicId, Description = question.Description, Notes = question.Notes }); return(""); //TODO - return new question id }
public async Task <ActionResult> AddQuestionToQuiz(IList <Question> questions, List <IFormFile> questionimg, List <string> listimgindex, string quizname, string quizdiff, string quizdescript) { try { var userId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; var uploadPath = Path.Combine(_he.WebRootPath, "images"); int imgCounter = 0; int isaindex = 0; Quiz quiz = new Quiz() { Name = quizname, Description = quizdescript, Difficulty = (Quiz.Difficulties)Enum.Parse(typeof(Quiz.Difficulties), quizdiff), QuestionCount = questions.Count(), ApplicationUserId = userId }; await _quizRepository.AddQuizAsync(quiz); foreach (var question in questions) { question.Quiz = quiz; await _questionRepository.AddQuestionAsync(question); if (Int16.Parse(listimgindex[isaindex]) == 1) { if (questionimg[imgCounter].Length > 0) { var filePath = Path.Combine(uploadPath, question.Id + ".jpg"); using (var fileStream = new FileStream(filePath, FileMode.Create)) { await questionimg[imgCounter].CopyToAsync(fileStream); } } imgCounter++; } isaindex++; } var result = await _quizRepository.GetAllQuizzesAsync(); return(View("Quizzes", result)); } catch (Exception ex) { Debug.WriteLine(ex.InnerException.Message); return(View("MyQuizzes")); } }
public async Task <IActionResult> Post([FromBody] ApplicationCore.Models.Question question) { if (!ModelState.IsValid) { return(BadRequest()); } if (question.QuestionChoices.Count < 4) { return(BadRequest("Question must have at least 4 choices.")); } if (!await _questionRepo.CategoryExistsAsync((int)question.CategoryId)) { return(BadRequest($"Category with id {question.CategoryId} does not exist.")); } var createdItem = await _questionRepo.AddQuestionAsync(question); return(CreatedAtAction( actionName: nameof(Get), routeValues: new { id = createdItem.QuestionId }, value: createdItem)); }