public override void Save() { DBCommand dbc = new DBCommand(DBCommand.TransactionType.WithTransaction); try { DataBase db = new StudentData(dbc); if (Student.PersonId == 0) { int studentId = db.Add(Student); if (Student.Doctors.Count > 0) { db = new DoctorData(dbc); foreach (Doctor doctor in Student.Doctors) { db.Allocate(doctor, studentId); } } if (Student.NextOfKin.Count > 0) { db = new NextOfKinData(dbc); foreach (NextOfKin nok in Student.NextOfKin) { if (nok.PersonId == 0) { nok.PersonId = db.Add(nok, studentId); } else { db.Allocate(nok, studentId); } } } if (Student.EmergencyContacts.Count > 0) { db = new EmergencyContactData(dbc); foreach (EmergencyContact ec in Student.EmergencyContacts) { //if (ec.PersonId == 0) //{ ec.PersonId = db.Add(ec, studentId); //} //db.Allocate(ec, studentId); } } if (Student.MedicalConditions.Count > 0) { MedicalConditionData mdc = new MedicalConditionData(dbc); foreach (MedicalCondition mc in Student.MedicalConditions) { mdc.Add(mc, studentId); } } } else { db.Update(Student); } dbc.CommitTransactions(); dbc.CloseConnection(); Student.RemovedObjects.Clear(); } catch (Exception ex) { dbc.rollbackTransactions(); dbc.CloseConnection(); throw new Exception(ex.Message); } }
public override void AllocateNextOfKin(NextOfKin nextOfKin) { DataBase db = new NextOfKinData(); db.Allocate(nextOfKin, Student.PersonId); }