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(); } }
public static void UpdateTeacher(TeacherInfo t) { if (!Util.IsValidEmail(t.Email)) { throw new ArgumentException("Email string is not a valid email!"); } UsersDAL.UpdateUser(t); using (SchoolJournalEntities context = new SchoolJournalEntities()) { Teacher teacherToUpdate = context.Set <Teacher>().Find(t.TeacherID); teacherToUpdate.Specialization = t.Specialization; teacherToUpdate.Category = t.Category; context.SaveChanges(); } }