public async Task <IActionResult> AddWordToList(string SpellingWord, int SpellingListId) { SpellingWord newWord; SpellingWord existingWord = await _context.SpellingWords.SingleOrDefaultAsync(w => w.Word == SpellingWord); // Creates a new word if it does not already exist, otherwise retreive existing word to add to list. if (existingWord == null) { newWord = new SpellingWord { Word = SpellingWord }; await _context.SpellingWords.AddAsync(newWord); } else { newWord = existingWord; } WordListAllocation newAllocation = new WordListAllocation() { SpellingWordId = newWord.Id, SpellingListId = SpellingListId }; await _context.WordListAllocations.AddAsync(newAllocation); await _context.SaveChangesAsync(); return(RedirectToAction("AssignWords", (new { SpellingListId = SpellingListId }))); }
public void GetSpellingWord(Action <SpellingWord, Exception> callback) { // Use this to connect to the actual data service var item = new SpellingWord("HelloSpellDesign", "Hello, Welcome to MVVM Light - this is Spelling Word Service"); callback(item, null); }
// GET: Student/ViewLists public async Task <IActionResult> ViewLists(int StudentId, int?SpellingListId) { ViewListsViewModel viewListsVM = new ViewListsViewModel(); viewListsVM.Student = await _context.Students.SingleOrDefaultAsync(s => s.StudentId == StudentId); // Get all group allocations for the student and add the group to a list List <StudentGroupAllocation> groupAllocations = await _context.StudentGroupAllocations.Where(a => a.StudentId == viewListsVM.Student.StudentId).ToListAsync(); List <SpellingGroup> studentGroups = new List <SpellingGroup>(); foreach (var allocation in groupAllocations) { SpellingGroup group = await _context.SpellingGroups.SingleOrDefaultAsync(g => g.SpellingGroupId == allocation.SpellingGroupId); studentGroups.Add(group); } viewListsVM.SpellingLists = new List <SpellingList>(); // Assign all spelling lists for each group the student is in to the View Model List of Spelling Lists foreach (var group in studentGroups) { List <ListGroupAllocation> listAllocations = await _context.ListGroupAllocations.Where(a => a.SpellingGroupId == group.SpellingGroupId).ToListAsync(); foreach (var a in listAllocations) { SpellingList list = await _context.SpellingLists.SingleOrDefaultAsync(l => l.SpellingListId == a.SpellingListId); viewListsVM.SpellingLists.Add(list); } } // Assing a spelling list to the active list if (SpellingListId == null) { viewListsVM.ActiveSpellingList = viewListsVM.SpellingLists.First(); } else { viewListsVM.ActiveSpellingList = viewListsVM.SpellingLists.SingleOrDefault(l => l.SpellingListId == SpellingListId); } // Get all the words associated with the Spelling list List <WordListAllocation> wordAllocations = await _context.WordListAllocations.Where(a => a.SpellingListId == viewListsVM.ActiveSpellingList.SpellingListId).ToListAsync(); viewListsVM.SpellingWords = new List <SpellingWord>(); foreach (var a in wordAllocations) { SpellingWord word = await _context.SpellingWords.SingleOrDefaultAsync(w => w.Id == a.SpellingWordId); viewListsVM.SpellingWords.Add(word); } return(View(viewListsVM)); }
private string formatInfoToSave(List <SpellingWord> list) { String words = ""; for (int i = 0; i < list.Count; i++) { SpellingWord currWord = list[i]; words += currWord.getWord() + "," + currWord.getImage() + "\r\n"; } return(words); }
public List <SpellingWord> getWordList() { var list = new List <SpellingWord>(); foreach (String line in lines) { String[] words = line.Split(delimiterChars); var spellingWord = new SpellingWord(words[0], words[1]); list.Add(spellingWord); } return(list); }