public void DeleteContact(string distinguishedName, string companyCode) { ExchangePowershell powershell = null; CPDatabase database = null; try { // Get company distinguished name database = new CPDatabase(); var contact = (from c in database.Contacts where c.DistinguishedName == distinguishedName select c).First(); powershell = new ExchangePowershell(StaticSettings.ExchangeURI, StaticSettings.Username, StaticSettings.DecryptedPassword, StaticSettings.ExchangeUseKerberos, StaticSettings.PrimaryDC); powershell.DeleteContact(distinguishedName); database.Contacts.Remove(contact); database.SaveChanges(); } catch (Exception ex) { ThrowEvent(Base.Enumerations.AlertID.FAILED, ex.Message); } finally { if (database != null) database.Dispose(); if (powershell != null) powershell.Dispose(); } }
private void Delete_Contact(string distinguishedName) { ExchangePowershell powershell = null; try { this.logger.Warn("Rolling back action... Deleting Exchange contact " + distinguishedName); powershell = new ExchangePowershell(StaticSettings.ExchangeURI, StaticSettings.Username, StaticSettings.DecryptedPassword, StaticSettings.ExchangeUseKerberos, StaticSettings.PrimaryDC); powershell.DeleteContact(distinguishedName); this.logger.Warn("Successfully removed Exchange contact " + distinguishedName); } catch (Exception ex) { this.logger.Error("Failed to roll back action... Deleting Exchange contact " + distinguishedName, ex); } finally { if (powershell != null) powershell.Dispose(); } }