Exemplo n.º 1
0
        public static Dictionary <string, TestsDB_SectionDTO> SelectSections(TestsDB_TestDTO test)
        {
            var random = new Random();

            if (test.AttemptSectionsNumber == 0)
            {
                test.AttemptSectionsNumber = test.Sections.Count();
            }

            var testSections = test.Sections.ToArray()
                               .OrderBy(x => random.Next())
                               .Take(test.AttemptSectionsNumber).ToArray();

            for (var i = 0; i < test.AttemptSectionsNumber; i++)
            {
                var testSection = testSections[i];

                if (testSection.Value.AttemptQuestionsNumber == 0)
                {
                    testSection.Value.AttemptQuestionsNumber = testSection.Value.Questions.Count();
                }

                testSections[i].Value.Questions = testSection.Value.Questions.OrderBy(x => random.Next())
                                                  .Take(testSection.Value.AttemptQuestionsNumber)
                                                  .ToDictionary(x => x.Key, x => x.Value);

                if (testSections[i].Value.Shuffle)
                {
                    testSections[i].Value.Questions = ShuffleQuestions(testSections[i].Value.Questions);
                }
            }

            test.Sections = testSections.ToDictionary(x => x.Key, x => x.Value);

            if (test.Shuffle)
            {
                test.Sections = ShuffleSections(test.Sections);
            }

            return(test.Sections);
        }
Exemplo n.º 2
0
        public async Task ReplaceTest(TestsDB_TestDTO updatedTest)
        {
            await TestWorker.Replace(updatedTest);

            await _redisCache.Del($"Test:{updatedTest.Id}");
        }
Exemplo n.º 3
0
 public async Task <ObjectId> InsertTest(TestsDB_TestDTO newTest) =>
 await TestWorker.InsertTest(newTest);
Exemplo n.º 4
0
        public static async Task <bool> Replace(TestsDB_TestDTO updatedTest)
        {
            var filter = Builders <TestsDB_TestDTO> .Filter.Eq("Id", updatedTest.Id);

            return((await MongoController.TestCollection.ReplaceOneAsync(filter, updatedTest)).MatchedCount == 1);
        }
Exemplo n.º 5
0
        public static async Task <ObjectId> InsertTest(TestsDB_TestDTO test)
        {
            await MongoController.TestCollection.InsertOneAsync(test);

            return(test.Id);
        }