public ActionResult QuizItem(Word inputWord) { // Marking is done in js in the view. // Not really using the Post at the moment for anything, // but need it for later to keep score, or something. // WordFileManager.getWordsFromFile(filepath) // Reads in a CSV file of words and genders. Constructs // Word objects for each, puts them in a list, and returns the list String mappedFilePath = Server.MapPath("~/App_Data/GermanWords.csv"); wordsInFile = wfm.getWordsFromFile(mappedFilePath); int nWords = wordsInFile.Count(); int randomIndex = rGen.Next(nWords); Word chosenWord = wordsInFile[randomIndex]; // For this quiz, we want the Nominative article chosenWord.CurrentDisplayVersion = chosenWord.DisplayNominative(); return View(chosenWord); }
public List<Word> getWordsFromFile(string dataFile) { Array rawFileContents = null; List<Word> wordHolder = new List<Word>(); if (System.IO.File.Exists(dataFile)) { rawFileContents = System.IO.File.ReadAllLines(dataFile); String[] wordData = new String[INFOFIELDS]; foreach (String s in rawFileContents) { wordData = s.Split(','); Word newWord = new Word(); newWord.WordLetters = wordData[WORDLETTERSPOSITION]; newWord.GenderNumber = Convert.ToInt16(wordData[GENDERCODEPOSITION]); newWord.Definition = wordData[DEFINITIONPOSITION]; wordHolder.Add(newWord); } } // if file exists return wordHolder; }