Exemple #1
0
        public QuestionViewModel CreateQuestion(QuestionViewModel question)
        {
            try
            {
                question.ID = questionRepository.CreateQuestion(map.ViewModelToEntity(question));

                return(question);
            }
            catch (Exception exception)
            {
                log.Error(exception);
                return(new QuestionViewModel());
            }
        }
Exemple #2
0
        public void Create([FromBody] ICollection <Question> Questions)
        {
            int questionID;

            // _repo.CreateQuestion(Question);
            foreach (Question question in Questions)
            {
                questionID = _repo.CreateQuestion(question);
                foreach (Answer answer in question.Answers)
                {
                    answer.QuestionId = questionID;
                    _answerRepo.CreateAnswer(answer);

                    if (question.Type == 2 || question.Type == 3)
                    {
                        answer.IsCorrect = true;
                    }
                }
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            int                idQuest = 0, deleteid;
            string             questiontext, requiretext, menu;
            bool               requirement, exit = false;
            QuestionType       type;
            List <Questions>   questionList       = new List <Questions>();
            StreamWriter       sw                 = new StreamWriter("C:\\Users\\Academia\\Documents\\david_rodriguezv\\Practicas\\Survey\\Test.txt");
            QuestionRepository questionRepository = new QuestionRepository(questionList);

            do
            {
                Console.Clear();
                Console.WriteLine("Menu \n 1. Add question \n 2. Delete question \n 3. Take quizz \n 4. Exit");
                menu = Console.ReadLine();
                switch (menu)
                {
                case "1":
                    Console.WriteLine("Type the question:");
                    questiontext = Console.ReadLine();
                    sw.Write(questiontext);
                    Console.WriteLine("Is your question required?");
                    requiretext = Console.ReadLine();
                    sw.WriteLine(requiretext);
                    if (requiretext == "yes")
                    {
                        requirement = true;
                    }
                    else
                    {
                        requirement = false;
                    }
                    Console.WriteLine("What type of question it it?");
                    type = 0;
                    questionRepository.CreateQuestion(new Questions(idQuest, questiontext, requirement, type));
                    idQuest++;
                    break;

                case "2":
                    Console.WriteLine("Which id do you want to delete?");
                    deleteid = Convert.ToInt32(Console.ReadLine());
                    questionRepository.DeleteQuestion(deleteid);
                    break;

                case "3":
                    foreach (Questions question in questionList)
                    {
                        Console.WriteLine(question.Id + " " + question.Text + " " + question.Isrequired + " " + question.QuestionType);
                    }
                    Console.ReadKey();
                    break;

                case "4":
                    exit = true;
                    break;

                default:
                    Console.WriteLine("Select a valid option");
                    Console.ReadKey();
                    break;
                }
            } while (exit == false);

            sw.Close();
        }
Exemple #4
0
        public static SuccessFailCode Execute(IServiceProvider services, Options opts)
        {
            try
            {
                var configuration = services.GetService <IConfiguration>();
                configuration.Bind(opts);

                var client = new DocumentClient(new Uri(opts.Cosmos.Endpoint), opts.Cosmos.Key);

                var title = opts.QuestionVersionKey.Split('-').Last();
                var questionSetRepository = new QuestionSetRepository(client, new OptionsWrapper <CosmosSettings>(opts.Cosmos));
                var questionSet           = new QuestionSet()
                {
                    AssessmentType     = "short",
                    Version            = 1,
                    Title              = title,
                    QuestionSetKey     = title.ToLower(),
                    MaxQuestions       = 40,
                    LastUpdated        = DateTime.Now,
                    PartitionKey       = "ncs",
                    IsCurrent          = true,
                    QuestionSetVersion = opts.QuestionVersionKey + "-1"
                };
                questionSetRepository.CreateOrUpdateQuestionSet(questionSet).GetAwaiter().GetResult();

                var questionRepository = new QuestionRepository(client, new OptionsWrapper <CosmosSettings>(opts.Cosmos));
                using (var fileStream = File.OpenRead(opts.CsvFile))
                    using (var streamReader = new StreamReader(fileStream))
                        using (var reader = new CsvReader(streamReader))
                        {
                            var questionPartitionKey = questionSet.QuestionSetVersion;
                            var questionNumber       = 1;

                            foreach (var question in reader.GetRecords <QuestionStatement>())
                            {
                                var questionId = $"{questionPartitionKey}-{questionNumber}";
                                Console.WriteLine($"Creating question id: {questionId}");

                                questionRepository.CreateQuestion(new Question {
                                    IsNegative   = question.IsFlipped == 1,
                                    Order        = questionNumber,
                                    QuestionId   = questionId,
                                    TraitCode    = question.Trait.ToUpper(),
                                    PartitionKey = questionPartitionKey,
                                    Texts        = new [] {
                                        new QuestionText {
                                            LanguageCode = "EN", Text = question.Statement
                                        }
                                    }
                                }).GetAwaiter().GetResult();

                                questionNumber++;
                            }
                        }
                return(SuccessFailCode.Succeed);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"An Error ocurred loading while loading questions to: {opts.Cosmos.Endpoint} - {opts.Cosmos.DatabaseName} -- {ex.Message}");
                Console.ForegroundColor = ConsoleColor.White;
                return(SuccessFailCode.Fail);
            }
        }
Exemple #5
0
        public void Post([FromBody] Question value)
        {
            QuestionRepository repository = new QuestionRepository(_mapper);

            repository.CreateQuestion(value);
        }