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 async Task <IActionResult> DeleteWordAllocation(int Id, int ActiveListId) { WordListAllocation allocation = await _context.WordListAllocations.SingleOrDefaultAsync(a => a.WordListAllocationId == Id); _context.WordListAllocations.Remove(allocation); await _context.SaveChangesAsync(); return(RedirectToAction("AssignWords", (new { SpellingListId = ActiveListId }))); }