public void UpdateContact(ContactEntity contactEntity) { var result = _directoryContext.ContactEntities. SingleOrDefault(p => p.ContactId == contactEntity.ContactId); if (result != null) { _directoryContext.Entry(result).CurrentValues.SetValues(contactEntity); _directoryContext.SaveChanges(); } }
public void AddCommunicationMethod(ContactEntity contactEntity, CommunicationMethodEntity communicationMethodEntity) { var result = _directoryContext.CommunicationMethodEntities .SingleOrDefault(p => p.Address == communicationMethodEntity.Address && p.TypeId == communicationMethodEntity.TypeId && p.ContactId == contactEntity.ContactId); if (result == null) { communicationMethodEntity.ContactId = contactEntity.ContactId; _directoryContext.CommunicationMethodEntities.Add(communicationMethodEntity); _directoryContext.SaveChanges(); _directoryContext.Entry(communicationMethodEntity).Reload(); } else { throw new System.Exception("An entry with this address is already exists"); } }
public void AddContact(ContactEntity contactEntity) { _directoryContext.ContactEntities.Add(contactEntity); _directoryContext.SaveChanges(); }