private void Create(CandidateWithHistory candidateWithHistory) { //Insert new person record to match with candidate record var personId = (int)_targetDatabase.Insert(candidateWithHistory.CandidatePerson.Person); candidateWithHistory.CandidatePerson.Candidate.PersonId = personId; //Insert candidate records var candidateId = (int)_targetDatabase.Insert(candidateWithHistory.CandidatePerson.Candidate); var schoolAttended = candidateWithHistory.CandidatePerson.SchoolAttended; if (schoolAttended != null) { //Insert school attended schoolAttended.CandidateId = candidateId; _targetDatabase.Insert(schoolAttended); } //Insert new candidate history records foreach (var candidateHistory in candidateWithHistory.CandidateHistory) { candidateHistory.CandidateId = candidateId; _targetDatabase.Insert(candidateHistory); } }
private void Update(CandidateWithHistory candidateWithHistory) { //update existing person _targetDatabase.UpdateSingle(candidateWithHistory.CandidatePerson.Person); //update existing candidate _targetDatabase.UpdateSingle(candidateWithHistory.CandidatePerson.Candidate); //Insert new candidate history records foreach (var candidateHistory in candidateWithHistory.CandidateHistory.Where(a => a.CandidateHistoryId == 0)) { _targetDatabase.Insert(candidateHistory); } var schoolAttended = candidateWithHistory.CandidatePerson.SchoolAttended; if (schoolAttended != null) { if (schoolAttended.SchoolAttendedId == 0) { //Insert school attended if not already present _targetDatabase.Insert(schoolAttended); } else { //Otherwise update _targetDatabase.UpdateSingle(schoolAttended); } } //Update existing candidate history records foreach (var candidateHistory in candidateWithHistory.CandidateHistory.Where(a => a.CandidateHistoryId != 0)) { _targetDatabase.UpdateSingle(candidateHistory); } }