Esempio n. 1
0
        public static void UpdateStudent(StudentInfo si)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {

                Student s = context.Set<Student>().Find(si.StudentID);
                if (s == null)
                    throw new ArgumentNullException("StudentID to update cannot be null!");

                if (!Util.IsValidEmail(si.Email))
                    throw new ArgumentException("Email string is not a valid email!");

                UsersDAL.UpdateUser(si);

                s.DateOfJoin = si.DateOfJoin;
                //find grade ID
                var gID = (from grade in context.Grades where (grade.GradeNo+grade.Section).Equals(si.GradeName) select grade.GradeID);
                if (gID.Count() > 0)
                {
                    s.GradeID = gID.First();
                }
                else throw new ArgumentException("Invalid grade name!");
                context.SaveChanges();
            }
        }
Esempio n. 2
0
        public static StudentInfo GetStudentInfo(int studentID)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                Student p = context.Set<Student>().Find(studentID);

                if (p != null)
                {
                    StudentInfo info = new StudentInfo(p);
                    return info;
                }
                else throw new ArgumentOutOfRangeException("Student ID was not found in the DB!");
            }
        }