protected override void OnParameterChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (base.Parameter.Any(a => a.Key == DataModelName))
     {
         this.CurrentDataModel = (Role)(base.Parameter.FirstOrDefault(a => a.Key == DataModelName).Value as Role).Clone();
         foreach (var v in dbContext.RoleModuleDb.GetList(a => a.RoleId == CurrentDataModel.Id))
         {
             SelectedModuleList.Add(ModuleList.FirstOrDefault(a => a.Id == v.ModuleId));
         }
         SelectedModuleList.CollectionChanged += SelectedModuleList_CollectionChanged;
         CurrentDataModel.PropertyChanged     += CurrentDataModel_PropertyChanged;
     }
 }
        public async Task <IActionResult> OnGetAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            StudentList = await _db.Students.AsNoTracking().ToListAsync();

            ModuleList = await _db.Modules.AsNoTracking().ToListAsync();

            ProgrammeModuleList = await _db.ProgrammeModules.AsNoTracking().ToListAsync();

            ProgrammeList = await _db.Programmes.AsNoTracking().ToListAsync();


            // Should only be one student returned here
            var students = StudentList.Where(s => s.StudentID == id)
                           .Select(s => s);

            if ((students != null) && (students.Count() == 1))
            {
                // Extract relevant details from the student object
                AssessmentResult.ProgrammeID = students.FirstOrDefault().ProgrammeID;
                AssessmentResult.StudentID   = students.FirstOrDefault().StudentID;
                StudentName = students.FirstOrDefault().ToString();

                // Get the relevant programme name
                ProgrammeName = ProgrammeList.Where(p => p.ProgrammeID == AssessmentResult.ProgrammeID)
                                .Select(p => p)
                                .FirstOrDefault().ProgrammeName;

                // Populate select module list for this programme
                if (ProgrammeModuleList.Count() != 0)
                {
                    var progMods = ProgrammeModuleList.Where(s => s.ProgrammeID == AssessmentResult.ProgrammeID)
                                   .Select(s => s);

                    if (progMods != null)
                    {
                        foreach (var progMod in progMods)
                        {
                            var mods = ModuleList.Where(s => s.ModuleID == progMod.ModuleID)
                                       .Select(s => s);

                            foreach (var mod in mods)
                            {
                                SelectedModuleList.Add(mod);
                            }
                        }
                        return(Page());
                    }
                    else
                    {
                        //Error - no programme assigned to this student
                        ErrorMessage = $"Error: there is no programme assigned to this student: {AssessmentResult.StudentID}";
                        return(RedirectToPage("/MyErrorPage", new { area = "ErrorPages", id = AssessmentResult.AssessmentResultID }));
                    }
                }
                else
                {
                    //Error - Prog Mods is null
                    ErrorMessage = "Error: the Programme - Modules table is empty; cannot process assessment submission";
                    return(RedirectToPage("/MyErrorPage", new { area = "ErrorPages", id = AssessmentResult.AssessmentResultID }));
                }
            }
            else
            {
                // Student not found
                return(NotFound());
            }
        }