コード例 #1
0
        private void registerStudentButton_Click(object sender, RoutedEventArgs e)
        {
            CourseRecordInformation information = MainHandlers.WindowManager.ClassRecords.SelectedClass;

            if (information != null)
            {
                string content = string.Empty;
                try
                {
                    if (MainHandlers.WindowManager.IsAdmin)
                    {
                        StudentRecordHandler student = ((AdminRecordHandler)MainHandlers.WindowManager.ViewHandler).SelectedStudent;
                        student.RegisterStudent(information);
                        content = string.Format("Student: {0} {1} was registered for: {2}", student.PersonalInformation.FirstName, student.PersonalInformation.LastName, information.CourseName);
                    }
                    else
                    {
                        StudentRecordHandler student = ((StudentRecordHandler)MainHandlers.WindowManager.ViewHandler);
                        student.RegisterStudent(information);
                        content = string.Format("Student: {0} {1} was registered for: {2}", student.PersonalInformation.FirstName, student.PersonalInformation.LastName, information.CourseName);
                    }
                }catch (Exception em)
                {
                    content = em.Message;
                }

                MessageBox.Show(content, "Ok");
            }
        }
コード例 #2
0
        public void RegisterStudent(CourseRecordInformation information)
        {
            TypeClassesPair pair = AcademicInformation.GetTypeClassPair("Registered");

            if (!AcademicInformation.ContainsClass(information.ClassNumber))
            {
                if (pair.Classes.Count > 3)
                {
                    if (Convert.ToDouble(AcademicInformation.GPA) > 3.5)
                    {
                        pair.Classes.Add(new ClassTakenInformation(information.CourseName, information.Department, information.ClassNumber, ""));
                    }
                    else
                    {
                        throw new Exception("Insufficeint GPA for the Student to register for more than 3 classes");
                    }
                }
                else
                {
                    pair.Classes.Add(new ClassTakenInformation(information.CourseName, information.Department, information.ClassNumber, ""));
                }
            }
            else
            {
                throw new Exception($"The student is already registered to: {information.CourseName}");
            }

            var filter = Builders <BsonDocument> .Filter.Eq("StudentID", PersonalInformation.ID);

            BsonDocument doc = new BsonDocument()
            {
                { "ClassName", $"{information.Department}{information.ClassNumber} - {information.CourseName}" }, { "Grade", "" }
            };
            var update = Builders <BsonDocument> .Update.AddToSet("AcademicInformation.Registered", doc);

            MainHandlers.DatabaseHandler.Database.GetCollection(Common.Models.Collections.Students).UpdateOne(filter, update);
        }