public void AddQuestion(Question newQuestion)
 {
     _questionRepository.AddQuestion(newQuestion);
 }
 public void AddQuestion(QuestionViewModel model)
 {
     _questionRepository.AddQuestion(model);
     return;
 }
        public void SetUpDatabase()
        {
            _repository = QuestionRepositoryFactory.CreateObjectDatabaseRespository(_dbPath);            

            _repository.AddQuestion(new QuizQuestion()
                {
                    QuestionText = "Question 1",
                    CorrectAnswer = "Correct answer",
                    WrongAnswer1 = "Wrong answer",
                    WrongAnswer2 = "Wrong answer",
                    WrongAnswer3 = "Wrong answer",
                    Difficulty = DifficultyLevel.Easy,
                });
            _repository.AddQuestion(new QuizQuestion()
                {
                    QuestionText = "Question 2",
                    CorrectAnswer = "Correct answer",
                    WrongAnswer1 = "Wrong answer",
                    WrongAnswer2 = "Wrong answer",
                    WrongAnswer3 = "Wrong answer",
                    Difficulty = DifficultyLevel.Easy,
                });
            _repository.AddQuestion(new QuizQuestion()
                {
                    QuestionText = "Question 3",
                    CorrectAnswer = "Correct answer",
                    WrongAnswer1 = "Wrong answer",
                    WrongAnswer2 = "Wrong answer",
                    WrongAnswer3 = "Wrong answer",
                    Difficulty = DifficultyLevel.Medium,
                });
            _repository.AddQuestion(new QuizQuestion()
                {
                    QuestionText = "Question 4",
                    CorrectAnswer = "Correct answer",
                    WrongAnswer1 = "Wrong answer",
                    WrongAnswer2 = "Wrong answer",
                    WrongAnswer3 = "Wrong answer",
                    Difficulty = DifficultyLevel.Medium,
                });
            _repository.AddQuestion(new QuizQuestion()
                {
                    QuestionText = "Question 5",
                    CorrectAnswer = "Correct answer",
                    WrongAnswer1 = "Wrong answer",
                    WrongAnswer2 = "Wrong answer",
                    WrongAnswer3 = "Wrong answer",
                    Difficulty = DifficultyLevel.Difficult,
                });
            _repository.AddQuestion(new QuizQuestion()
                {
                    QuestionText = "Question 6",
                    CorrectAnswer = "Correct answer",
                    WrongAnswer1 = "Wrong answer",
                    WrongAnswer2 = "Wrong answer",
                    WrongAnswer3 = "Wrong answer",
                    Difficulty = DifficultyLevel.Difficult,
                });
            _repository.AddQuestion(new QuizQuestion()
                {
                    QuestionText = "Question 7",
                    CorrectAnswer = "Correct answer",
                    WrongAnswer1 = "Wrong answer",
                    WrongAnswer2 = "Wrong answer",
                    WrongAnswer3 = "Wrong answer",
                    Difficulty = DifficultyLevel.Unknown,
                });
        }
Esempio n. 4
0
 public int AddQuestion(AddQuestionRequest model)
 {
     return(_questionRepository.AddQuestion(model));
 }
Esempio n. 5
0
        public async Task <ReturnQuestionDto> AddQuestion(string orgId, AddQuestionDto question)
        {
            try
            {
                bool isOrgValid = Guid.TryParse(orgId, out Guid orgPublicId);
                if (!isOrgValid)
                {
                    _customExceptionValidationService.CustomValidation("Invalid Organization Id.", HttpStatusCode.BadRequest);
                }
                if (question.Question == null || question.Options.Count < 2 || question.SubjectId == null)
                {
                    _customExceptionValidationService.CustomValidation("PLease provide correct data.", HttpStatusCode.BadRequest);
                }
                bool isSubjectValid = Guid.TryParse(question.SubjectId, out Guid subjectPublicId);
                if (!isSubjectValid)
                {
                    _customExceptionValidationService.CustomValidation("Invalid Subject Id.", HttpStatusCode.BadRequest);
                }
                var orgData = _orgRepository.GetOrganizationByPublicId(orgPublicId);
                if (orgData == null)
                {
                    _customExceptionValidationService.CustomValidation("No Organization Registered.", HttpStatusCode.NotFound);
                }
                var subjectdata = _subjectRepository.GetSubjectByPublicId(subjectPublicId);
                if (subjectdata == null)
                {
                    _customExceptionValidationService.CustomValidation("Incorrect Subject.", HttpStatusCode.NotFound);
                }
                var dbQuestionModel = new OrgQuestion
                {
                    Question            = question.Question,
                    SubjectId           = subjectdata.Id,
                    PublicId            = Guid.NewGuid(),
                    CreatedDate         = System.DateTime.UtcNow,
                    LastUpdatedDateTime = System.DateTime.UtcNow,
                    OrganizationId      = orgData.Id
                };
                var questionOptions = new List <QuestionOption>();
                foreach (var option in question.Options)
                {
                    var q = new QuestionOption
                    {
                        QOption     = option.Option,
                        IsCorrect   = option.IsCorrect,
                        QuestionId  = dbQuestionModel.Id,
                        OrgQuestion = dbQuestionModel,
                        PublicId    = Guid.NewGuid()
                    };
                    questionOptions.Add(q);
                }
                dbQuestionModel.QuestionOption = questionOptions;
                await _questinRepository.AddQuestion(dbQuestionModel);

                return(new ReturnQuestionDto {
                    QuestionId = dbQuestionModel.PublicId
                });
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 6
0
        public void SetUpDatabase()
        {
            _repository = QuestionRepositoryFactory.CreateObjectDatabaseRespository(_dbPath);

            _repository.AddQuestion(new QuizQuestion()
            {
                QuestionText  = "Question 1",
                CorrectAnswer = "Correct answer",
                WrongAnswer1  = "Wrong answer",
                WrongAnswer2  = "Wrong answer",
                WrongAnswer3  = "Wrong answer",
                Difficulty    = DifficultyLevel.Easy,
            });
            _repository.AddQuestion(new QuizQuestion()
            {
                QuestionText  = "Question 2",
                CorrectAnswer = "Correct answer",
                WrongAnswer1  = "Wrong answer",
                WrongAnswer2  = "Wrong answer",
                WrongAnswer3  = "Wrong answer",
                Difficulty    = DifficultyLevel.Easy,
            });
            _repository.AddQuestion(new QuizQuestion()
            {
                QuestionText  = "Question 3",
                CorrectAnswer = "Correct answer",
                WrongAnswer1  = "Wrong answer",
                WrongAnswer2  = "Wrong answer",
                WrongAnswer3  = "Wrong answer",
                Difficulty    = DifficultyLevel.Medium,
            });
            _repository.AddQuestion(new QuizQuestion()
            {
                QuestionText  = "Question 4",
                CorrectAnswer = "Correct answer",
                WrongAnswer1  = "Wrong answer",
                WrongAnswer2  = "Wrong answer",
                WrongAnswer3  = "Wrong answer",
                Difficulty    = DifficultyLevel.Medium,
            });
            _repository.AddQuestion(new QuizQuestion()
            {
                QuestionText  = "Question 5",
                CorrectAnswer = "Correct answer",
                WrongAnswer1  = "Wrong answer",
                WrongAnswer2  = "Wrong answer",
                WrongAnswer3  = "Wrong answer",
                Difficulty    = DifficultyLevel.Difficult,
            });
            _repository.AddQuestion(new QuizQuestion()
            {
                QuestionText  = "Question 6",
                CorrectAnswer = "Correct answer",
                WrongAnswer1  = "Wrong answer",
                WrongAnswer2  = "Wrong answer",
                WrongAnswer3  = "Wrong answer",
                Difficulty    = DifficultyLevel.Difficult,
            });
            _repository.AddQuestion(new QuizQuestion()
            {
                QuestionText  = "Question 7",
                CorrectAnswer = "Correct answer",
                WrongAnswer1  = "Wrong answer",
                WrongAnswer2  = "Wrong answer",
                WrongAnswer3  = "Wrong answer",
                Difficulty    = DifficultyLevel.Unknown,
            });
        }
Esempio n. 7
0
 int IQuestionService.AddQuestion(Question question)
 {
     return(questionRepository.AddQuestion(question));
 }
Esempio n. 8
0
 // Add new question.
 public void AddQuestion(Question question)
 {
     _questionRepository.AddQuestion(question);
 }
Esempio n. 9
0
        public async Task <IActionResult> Create(QuestionViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                var cat = _categoryRepository.GetCategories().ToList();
                ViewBag.Categories = new SelectList(cat, "Id", "Name", vm.CategoryId);
            }
            var pathUrl = string.Empty;

            if (vm.Image != null && vm.Image.Length > 0)
            {
                var guid = Guid.NewGuid().ToString();
                var file = $"{guid}.jpg";

                pathUrl = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\JuegosMentales", file);

                using (var stream = new FileStream(pathUrl, FileMode.Create))
                {
                    await vm.Image.CopyToAsync(stream);
                }

                pathUrl = $"~/images/JuegosMentales/{file}";
            }

            var question = new Question
            {
                AnswerRestrospective = vm.AnswerRestrospective,
                CategoryId           = vm.CategoryId,
                Questionant          = vm.Questionant,
                ImagenUrl            = pathUrl
            };

            // var Choises = new List<Choise>();

            question.Choises.Add(new Choise
            {
                IsCorrect = vm.Choise1IsCorrect,
                Option    = vm.Choise1,
            });
            question.Choises.Add(new Choise
            {
                IsCorrect = vm.Choise2IsCorrect,
                Option    = vm.Choise2,
            });
            question.Choises.Add(new Choise
            {
                IsCorrect = vm.Choise3IsCorrect,
                Option    = vm.Choise3,
            });
            question.Choises.Add(new Choise
            {
                IsCorrect = vm.Choise4IsCorrect,
                Option    = vm.Choise4,
            });

            _repository.AddQuestion(question);

            await _repository.SaveAllAsync();

            return(RedirectToAction("Detail", "Questions", new { id = question.Id }));
        }
Esempio n. 10
0
 public async Task <ActionResult> PostQuestion(Question question)
 {
     return(await _repository.AddQuestion(question));
 }
Esempio n. 11
0
 /// <summary>
 ///     Adds new question.
 /// </summary>
 /// <param name="question">The question.</param>
 /// <returns>
 ///     The <see cref="Task" />.
 /// </returns>
 public Task <IdResult> AddNewQuestion(Question question)
 {
     return(_questionRepository.AddQuestion(question));
 }
Esempio n. 12
0
        public string Get(string setting)
        {
            if (setting == "init")
            {
                _questionRepository.RemoveAllQuestions();


                _questionRepository.AddQuestion(new Question()
                {
                    Id          = "1",
                    Body        = "Test note 1",
                    UpdatedOn   = DateTime.Now,
                    UserId      = 1,
                    HeaderImage = new QuestionImage
                    {
                        ImageSize    = 10,
                        Url          = "http://localhost/image1.png",
                        ThumbnailUrl = "http://localhost/image1_small.png"
                    }
                });

                _questionRepository.AddQuestion(new Question()
                {
                    Id          = "2",
                    Body        = "Test note 2",
                    UpdatedOn   = DateTime.Now,
                    UserId      = 1,
                    HeaderImage = new QuestionImage
                    {
                        ImageSize    = 13,
                        Url          = "http://localhost/image2.png",
                        ThumbnailUrl = "http://localhost/image2_small.png"
                    }
                });

                _questionRepository.AddQuestion(new Question()
                {
                    Id          = "3",
                    Body        = "Test note 3",
                    UpdatedOn   = DateTime.Now,
                    UserId      = 1,
                    HeaderImage = new QuestionImage
                    {
                        ImageSize    = 14,
                        Url          = "http://localhost/image3.png",
                        ThumbnailUrl = "http://localhost/image3_small.png"
                    }
                });

                _questionRepository.AddQuestion(new Question()
                {
                    Id          = "4",
                    Body        = "Test note 4",
                    UpdatedOn   = DateTime.Now,
                    UserId      = 1,
                    HeaderImage = new QuestionImage
                    {
                        ImageSize    = 15,
                        Url          = "http://localhost/image4.png",
                        ThumbnailUrl = "http://localhost/image4_small.png"
                    }
                });

                return("Database NotesDb was created, and collection 'Notes' was filled with 4 sample items");
            }

            return("Unknown");
        }