/// <summary> /// Deletes a company. Does not check for existing users. Is destructive /// </summary> /// <param name="companyCode"></param> public void Delete(string companyCode) { OrganizationalUnits organizationalUnits = null; try { if (string.IsNullOrEmpty(companyCode)) { throw new MissingFieldException("", "CompanyCode"); } organizationalUnits = new OrganizationalUnits(Settings.Username, Settings.DecryptedPassword, Settings.PrimaryDC); // Find the resellers from SQL var company = (from c in db.Companies where c.IsReseller where c.CompanyCode == companyCode select c).First(); if (company == null) { throw new ArgumentNullException(companyCode); } else { // SAFE DELETE OFF! DESTRUCTIVE! WILL DELETE ALL USERS AND OBJECTS IN COMPANY!! organizationalUnits.Delete(company.DistinguishedName, false); // Remove all companiesby calling stored procedure db.spDeleteCompany(company.CompanyCode); log.InfoFormat("Successfully deleted company {0}.", company.CompanyName); } } catch (Exception ex) { log.ErrorFormat("Error deleting company: {0}", ex.ToString()); throw; } finally { if (organizationalUnits != null) { organizationalUnits.Dispose(); } } }