/// <summary>
 /// <para>Deletes a sales agent from an accountId and a salesAgentId.</para>
 /// </summary>
 /// <param name="accountId">The account Id of the requestor. The account Id should own the sales agent being deleted.</param>
 /// <param name="salesAgent">The Id of the sales agent to be deleted.</param>
 /// <returns>Returns true if the deletion was successful or false if not.</returns>
 public bool DeleteSalesAgent(int accountId, int salesAgentId)
 {
     return(SalesAgentManager.DeleteSalesAgent(accountId, salesAgentId));
 }
        /// <summary>
        /// Deletes an account and all access codes, ship fits, sales agents and their contracts.
        /// </summary>
        /// <param name="accountId">The account Id being deleted.</param>
        /// <returns>Returns a validation result object.</returns>
        public IValidationResult DeleteAccount(int accountId)
        {
            IValidationResult validationResult = new ValidationResult();

            // Delete all account ship fits, components and related contracts.
            var accountShipFits = ShipFitManager.GetShipFitList(accountId);

            foreach (var shipFit in accountShipFits)
            {
                if (ShipFitManager.DeleteShipFit(accountId, shipFit.ShipFitId) == false)
                {
                    validationResult.AddError(shipFit.ShipFitId.ToString(), "Error while deleting ship fit: " + shipFit.ShipFitId.ToString());
                }
            }

            // Delete all account sales agents.
            var accountSalesAgents = SalesAgentManager.GetSalesAgents(accountId);

            foreach (var salesAgent in accountSalesAgents)
            {
                if (SalesAgentManager.DeleteSalesAgent(accountId, salesAgent.SalesAgentId) == false)
                {
                    validationResult.AddError(salesAgent.SalesAgentId.ToString(), "Error while deleting sales agent: " + salesAgent.SalesAgentId.ToString());
                }
            }

            // Delete all account doctrines.
            var accountDoctrines = ShipFitManager.GetDoctrineList(accountId);

            foreach (var doctrine in accountDoctrines)
            {
                if (ShipFitManager.DeleteDoctrine(accountId, doctrine.DoctrineId) == false)
                {
                    validationResult.AddError(doctrine.DoctrineId.ToString(), "Error while deleting doctrine: " + doctrine.DoctrineId.ToString());
                }
            }

            // Delete all account access codes.
            var accountAccessCodes = AccountManager.GetAccessCodes(accountId);

            foreach (var accessCode in accountAccessCodes)
            {
                if (AccountManager.DeleteAccessCode(accountId, accessCode.AccessCodeId) == false)
                {
                    validationResult.AddError(accessCode.AccessCodeId.ToString(), "Error while deleting access code: " + accessCode.AccessCodeId.ToString());
                }
            }

            // Delete all notification recipients.
            var accountNotificationRecipients = AccountManager.GetNotificationRecipients(accountId);

            foreach (var notificationRecipient in accountNotificationRecipients)
            {
                if (AccountManager.DeleteNotificationRecipient(accountId, notificationRecipient.NotificationRecipientId) == false)
                {
                    validationResult.AddError(notificationRecipient.NotificationRecipientId.ToString(), "Error while deleting notification recipient: " + notificationRecipient.NotificationRecipientId.ToString());
                }
            }

            // Delete the account.
            if (AccountManager.DeleteAccount(accountId) == false)
            {
                validationResult.AddError(accountId.ToString(), "Error while deleting account: " + accountId.ToString());
            }

            try
            {
                // Delete the account setting profile.
                var settingProfile = this.GetAccountSettingProfile(accountId);
                if (AccountManager.DeleteSettingProfile(accountId, settingProfile.SettingProfileId) == false)
                {
                    validationResult.AddError(settingProfile.SettingProfileId.ToString(), "Error while deleting setting profile: " + settingProfile.SettingProfileId.ToString());
                }
            }
            catch (System.ArgumentException e)
            {
                // The setting profile did not exist. Add an error to the validation result object.
                validationResult.AddError("SettingProfile.Exists" + accountId.ToString(), "The setting profile did not exist for account id: " + accountId.ToString());
            }
            catch (Exception)
            {
                throw;
            }

            return(validationResult);
        }