Example #1
0
        /// <summary>
        /// Deletes a <see cref="IGatewayProviderSettings"/>
        /// </summary>
        /// <param name="gatewayProviderSettings"></param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param>
        public void Delete(IGatewayProviderSettings gatewayProviderSettings, bool raiseEvents = true)
        {
            if (raiseEvents)
            {
                Deleting.RaiseEvent(new DeleteEventArgs <IGatewayProviderSettings>(gatewayProviderSettings), this);
            }

            // delete associated methods
            switch (gatewayProviderSettings.GatewayProviderType)
            {
            case GatewayProviderType.Payment:
                var paymentMethods = _paymentMethodService.GetPaymentMethodsByProviderKey(gatewayProviderSettings.Key).ToArray();
                if (paymentMethods.Any())
                {
                    _paymentMethodService.Delete(paymentMethods);
                }
                break;

            case GatewayProviderType.Shipping:
                var shippingMethods = _shipMethodService.GetShipMethodsByProviderKey(gatewayProviderSettings.Key).ToArray();
                if (shippingMethods.Any())
                {
                    _shipMethodService.Delete(shippingMethods);
                }
                break;

            case GatewayProviderType.Taxation:
                var taxMethods = _taxMethodService.GetTaxMethodsByProviderKey(gatewayProviderSettings.Key).ToArray();
                if (taxMethods.Any())
                {
                    _taxMethodService.Delete(taxMethods);
                }
                break;

            case GatewayProviderType.Notification:
                var notificationMethods =
                    _notificationMethodService.GetNotifcationMethodsByProviderKey(gatewayProviderSettings.Key).ToArray();
                if (notificationMethods.Any())
                {
                    _notificationMethodService.Delete(notificationMethods);
                }
                break;
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateGatewayProviderRepository(uow))
                {
                    repository.Delete(gatewayProviderSettings);
                    uow.Commit();
                }
            }
            if (raiseEvents)
            {
                Deleted.RaiseEvent(new DeleteEventArgs <IGatewayProviderSettings>(gatewayProviderSettings), this);
            }
        }