コード例 #1
0
        public IActionResult Assign(AssignStudentsViewModel model)
        {
            var student = model.Students.Where(s => s.IsChecked).Select(s => s.Id);

            repository.SetStudentsToCourse(model.Id, student);
            return(RedirectToAction("Course", "Course"));
        }
コード例 #2
0
        public IActionResult Assign(int id)
        {
            var allstudents = this.repository.GetAllStudents();
            var course      = repository.GetCourse(id);
            var model       = new AssignStudentsViewModel();

            if (course != null)
            {
                model.Id         = id;
                model.CourseName = course.Name;
                model.StartDate  = course.StartDate;
            }

            model.Students = new List <StudentViewModel>();

            foreach (var student in allstudents)
            {
                model.Students.Add(new StudentViewModel()
                {
                    Id        = student.Id,
                    Name      = student.Name,
                    IsChecked = course.Students.Any(s => s.StudentId == student.Id)
                });
            }

            return(View(model));
        }
コード例 #3
0
        // GET: Teacher/AssignStudents
        // Assign students to Spelling Groups
        public async Task <IActionResult> AssignStudents(int?SpellingGroupId)
        {
            AssignStudentsViewModel assignStudentsVM = new AssignStudentsViewModel();

            assignStudentsVM.SpellingGroups = await _context.SpellingGroups.Where(g => g.TeacherUsername == User.Identity.Name).ToListAsync();

            assignStudentsVM.AssignedStudents   = new List <Student>();
            assignStudentsVM.UnassignedStudents = new List <Student>();

            // Assign first SpellingGroup in list to ActiveSpellingGroup.
            if (SpellingGroupId == null && assignStudentsVM.SpellingGroups.Count != 0)
            {
                SpellingGroupId = assignStudentsVM.SpellingGroups[0].SpellingGroupId;
            }

            if (SpellingGroupId != null)
            {
                // Get activated spelling group.
                assignStudentsVM.ActiveSpellingGroup = await _context.SpellingGroups.SingleOrDefaultAsync(g => g.SpellingGroupId == SpellingGroupId);

                ViewData["GroupMessage"] = "";

                // Get allocated students for active spelling group.
                var allocations = _context.StudentGroupAllocations.Where(a => a.SpellingGroupId == assignStudentsVM.ActiveSpellingGroup.SpellingGroupId).ToList();

                // Assign active group students to view model.
                foreach (var allocation in allocations)
                {
                    assignStudentsVM.AssignedStudents.Add(await _context.Students.SingleOrDefaultAsync(s => s.StudentId == allocation.StudentId));
                }

                // Assign unallocated students for active spelling group to Unassigned students list.
                var allStudents = _context.Students.Where(s => s.TeacherUsername == User.Identity.Name).ToList();

                foreach (var student in allStudents)
                {
                    bool allocated = false;
                    foreach (var allocation in allocations)
                    {
                        if (student.StudentId == allocation.StudentId)
                        {
                            allocated = true;
                        }
                    }
                    if (!allocated)
                    {
                        assignStudentsVM.UnassignedStudents.Add(student);
                    }
                }
            }
            else
            {
                ViewData["GroupMessage"] = "You have no groups.";
            }

            return(View(assignStudentsVM));
        }