private PersonContactInfo GetContactData(string contactType, IEnumerable<PersonContactInfo> contactsForPerson, out bool found) { PersonContactInfo pci = null; PersonContactType pct = null; found = false; if (contactsForPerson != null) { pci = contactsForPerson.FirstOrDefault(x => x.PersonContactType.Title.Equals(contactType, StringComparison.InvariantCultureIgnoreCase)); } if (pci == null) { pct = unitOfWork.context.PersonContactTypes.FirstOrDefault(x => x.Title.Equals(contactType, StringComparison.InvariantCultureIgnoreCase)); if (pct == null) { pct = unitOfWork.PersonContactTypeRepository.Insert(new PersonContactType() { Title = contactType }); unitOfWork.Save(); } pci = new PersonContactInfo() { PersonContactTypeID = pct.PersonContactTypeID }; } else { found = true; return pci; } //if (contactsForPerson != null || contactsForPerson.Any(x => x.PersonContactType.Title.Equals(contactType, StringComparison.InvariantCultureIgnoreCase))) //{ // pci = contactsForPerson.FirstOrDefault(x => x.PersonContactType.Title.Equals(contactType, StringComparison.InvariantCultureIgnoreCase)); // if (pci == null) // { // pci = new PersonContactInfo(); // } // else // { // found = true; // } //} //else //{ // pci = unitOfWork.PersonContactTypeRepository.Insert(new PersonContactType() { Title = contactType }); // unitOfWork.Save(); // pci = new PersonContactInfo(); //} return pci; }
private void ChangeModelStateForContactInfo(bool isNew, PersonContactInfo personContactInfo) { if (isNew) { unitOfWork.PersonContactInfoRepository.Insert(personContactInfo); } else { unitOfWork.PersonContactInfoRepository.Update(personContactInfo); } }