コード例 #1
0
        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 })));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        // 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));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }