public ContactEntity Create(ContactEntity entity) { using (IDatabaseProvider provider = ProviderFactory.GetProvider(_connectionStringName)) { return provider.Insert<ContactEntity>(entity); } }
public static ContactEntity GetItemForInsert() { ContactEntity entity = new ContactEntity() { ContactTypeId = ContactDetailsHelpers.CreateContactType().Id, EntityId = ContactDetailsHelpers.CreateEntity().Id, Value = "Contact1", Preferred = true, DeletedDate = DateTime.MinValue }; return entity; }
public ContactEntity Update(ContactEntity entity) { using (IDatabaseProvider provider = ProviderFactory.GetProvider(_connectionStringName)) { ContactEntity entityToUpdate = Read(entity.Id); if (entityToUpdate == null) throw new DataAccessException("Item not found"); // This should not happen seeing that validation should check. entityToUpdate = UpdateProperties(entity, entityToUpdate); provider.Update<ContactEntity>(entityToUpdate); return entityToUpdate; } }
public ContactEntity Delete(ContactEntity entity) { entity.DeletedDate = DateTime.UtcNow; return Update(entity); }
private ContactEntity UpdateProperties(ContactEntity entity, ContactEntity entityToUpdate) { entityToUpdate.ContactTypeId = entity.ContactTypeId; entityToUpdate.EntityId = entity.EntityId; entityToUpdate.Value = entity.Value; entityToUpdate.Preferred = entity.Preferred; entityToUpdate.DeletedDate = entity.DeletedDate; return entityToUpdate; }
private static void CreateContacts() { ContactRepository repository = new ContactRepository(ConfigSettings.MySqlDatabaseConnectionName); ContactEntity entity = new ContactEntity() { ContactTypeId = _contactTypeEntities[0].Id, EntityId = _entityEntities[0].Id, Value = "*****@*****.**", Preferred = true, DeletedDate = DateTime.MinValue }; ContactEntity mEntity = new ContactEntity() { ContactTypeId = _contactTypeEntities[1].Id, EntityId = _entityEntities[1].Id, Value = "0768827423", Preferred = true, DeletedDate = DateTime.MinValue }; entity = repository.Create(entity); mEntity = repository.Create(mEntity); _contactEntities.Add(entity); _contactEntities.Add(mEntity); }