private static void SaveData(ICollection <FamilyParserModel> parsedFamilies, IDataFactory dataFactory) { parsedFamilies.ToList().ForEach(f => { var family = f.ParseToFamily(dataFactory); dataFactory.AddFamily(family); dataFactory.SaveAllChanges(); f.Visits.ToList().ForEach(v => { var visit = v.ParseToVisit(dataFactory); visit.FamilyId = family.Id; visit.UserId = family.AssignedStaffMember.Id; dataFactory.AddVisit(visit); }); var children = family.Children.ToList(); var fchildren = f.Children.ToList(); for (int i = 0; i < children.Count; i++) { var child = children[i]; fchildren[i].MedicalRecords.ToList().ForEach(mr => { var medicalRecord = mr.ParseToMedicalRecord(); medicalRecord.ChildId = child.Id; dataFactory.AddMedicalRecord(medicalRecord); }); } }); dataFactory.SaveAllChanges(); }