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);
            }
        }
        public ActionResult DeleteConfirmed(ReasonViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            //AFTER
            if (ModelState.IsValid)
            {
                var temp = _ShipMethodService.Find(vm.id);

                LogList.Add(new LogTypeViewModel
                {
                    ExObj = temp,
                });

                _ShipMethodService.Delete(vm.id);
                XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);
                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(PartialView("_Reason", vm));
                }

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ShipMethod).DocumentTypeId,
                    DocId           = vm.id,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    UserRemark      = vm.Reason,
                    xEModifications = Modifications,
                }));
                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }