public IEnumerable <PickerTestModel> BuildPickerTest( ITestTypes testType, int anserOptionsCount ) { var testData = this.GetTestData(testType); var wordCount = testData.Count; var pickerModels = new List <PickerTestModel>(); if (!testData.Any()) { return(pickerModels); } var random = new Random(); for (int i = 0; i < wordCount; i++) { var answerIndex = random.Next(anserOptionsCount); var answer = testType.IsEnRu ? testData[i].RussianWord.RuWord : testData[i].EnglishWord.EnWord; var testWord = testType.IsEnRu ? testData[i].EnglishWord.EnWord : testData[i].RussianWord.RuWord; if (testWord == null || answer == null) { return(pickerModels); } var randAnswer = GetAnswerOptions( answer, i, this._wordsCollection, testType.IsEnRu, anserOptionsCount ); var pickerTestModel = new PickerTestModel { AnswerId = answerIndex, Word = testWord, WordId = testData[i].Id, Answers = randAnswer.ToList(), Example = testData[i].Example }; pickerTestModel.Answers[answerIndex] = answer; pickerModels.Add(pickerTestModel); } return(pickerModels); }
private IEnumerable <PickerTestModel> PickerTest(int userId, bool isEnRuTest) { var enRuWordsForTest = Get10EnRuWords(userId, WordCount); var wordCount = enRuWordsForTest.Count; var pickerModels = new List <PickerTestModel>(); if (!enRuWordsForTest.Any()) { return(pickerModels); } var random = new Random(); for (int i = 0; i < wordCount; i++) { var answerIndex = random.Next(4); var answer = isEnRuTest ? enRuWordsForTest[i].RussianWord.RuWord : enRuWordsForTest[i].EnglishWord.EnWord; var tested = isEnRuTest ? enRuWordsForTest[i].EnglishWord.EnWord : enRuWordsForTest[i].RussianWord.RuWord; if (tested == null || answer == null) { return(pickerModels); } var randAnswer = Get4RandonWords(answer, i, userId, isEnRuTest); var pickerTestModel = new PickerTestModel { AnswerId = answerIndex, Word = tested, WordId = enRuWordsForTest[i].Id, Answers = randAnswer.ToList(), Example = enRuWordsForTest[i].Example }; pickerTestModel.Answers[answerIndex] = answer; pickerModels.Add(pickerTestModel); } return(pickerModels); }