public async Task <IActionResult> CreateSpellingList(SpellingListViewModel spellingListVM)
        {
            if (ModelState.IsValid)
            {
                SpellingList newSpellingList = new SpellingList()
                {
                    Name            = spellingListVM.Name,
                    Description     = spellingListVM.Description,
                    TeacherUsername = User.Identity.Name
                };

                try
                {
                    await _context.SpellingLists.AddAsync(newSpellingList);

                    await _context.SaveChangesAsync();

                    ViewData["message"] = $"You have successfully added the Spelling List named {newSpellingList.Name}";
                }
                catch (Exception ex)
                {
                    ViewData["message"] = "There was an error updating the database. Please try again.";
                }
            }
            ModelState.Clear();

            return(View());
        }
Exemple #2
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));
        }
Exemple #3
0
    public void SelectList(SpellingList list, GameObject gameObject)
    {
        int index = FindIndexFromName(list.name);

        currIndex = index;
        wordList.Clear();
        foreach (string word in masterList[currIndex].list)
        {
            wordList.Add(word, 0);
        }
        UpdateWords();
    }
Exemple #4
0
 public void AddList(string listName)
 {
     listName = listName.Trim();
     Debug.Log(listName + "yelp");
     if (listName != "" && !IsDuplicateListName(listName) && listName != "\n")
     {
         GameObject    temp           = Instantiate(listPrefab, parentList.transform);
         SelectList    selectListComp = temp.GetComponent <SelectList>();
         RemoveList    removeListComp = temp.GetComponentInChildren <RemoveList>();
         List <string> list           = new List <string>();
         SpellingList  newSpellList   = new SpellingList(list, listName, masterList.Count);
         temp.GetComponentInChildren <Text>().text = listName;
         selectListComp.spellList = newSpellList;
         removeListComp.spellList = newSpellList;
         masterList.Add(newSpellList);
         gameData.UpdateMasterList(masterList);
         SelectList(newSpellList, temp);
         SaveLoadManager.Save(gameData);
     }
 }
Exemple #5
0
    public void RemoveList(SpellingList list)
    {
        Debug.Log(list.name + " " + FindIndexFromName(list.name));
        Transform[] children = parentWord.GetComponentsInChildren <Transform>();

        if (currIndex == FindIndexFromName(list.name) || masterList.Count - 1 == 0)
        {
            foreach (Transform child in children)
            {
                if (child.name != "Content")
                {
                    GameObject.Destroy(child.gameObject);
                }
            }
        }
        masterList.RemoveAt(FindIndexFromName(list.name));
        gameData.UpdateMasterList(masterList);

        SaveLoadManager.Save(gameData);
    }