public SavePaymentGatewaysSettingsResult Add(SavePaymentGatewaysSettingsData model) { var validationResult = new SavePaymentGatewaySettingsValidator(_repository, true).Validate(model); if (!validationResult.IsValid) { throw new RegoValidationException(validationResult); } var setting = new PaymentGatewaySettings { Id = Guid.NewGuid(), BrandId = model.Brand, OnlinePaymentMethodName = model.OnlinePaymentMethodName, PaymentGatewayName = model.PaymentGatewayName, Channel = model.Channel, EntryPoint = model.EntryPoint, Remarks = model.Remarks, Status = Status.Inactive, DateCreated = _paymentQueries.GetBrandDateTimeOffset(model.Brand), CreatedBy = _actorInfoProvider.Actor.UserName }; _repository.PaymentGatewaySettings.Add(setting); using (var scope = CustomTransactionScope.GetTransactionScope()) { _repository.SaveChanges(); _eventBus.Publish(new PaymentGatewaySettingCreated { Id = setting.Id, CreatedBy = setting.CreatedBy, CreatedDate = setting.DateCreated, OnlinePaymentMethodName = setting.OnlinePaymentMethodName, PaymentGatewayName = setting.PaymentGatewayName, Channel = setting.Channel, EntryPoint = setting.EntryPoint, BrandId = setting.BrandId }); scope.Complete(); } return(new SavePaymentGatewaysSettingsResult { PaymentGatewaySettingsId = setting.Id }); }
public SavePaymentGatewaysSettingsResult Edit(SavePaymentGatewaysSettingsData model) { var validationResult = new SavePaymentGatewaySettingsValidator(_repository, false).Validate(model); if (!validationResult.IsValid) { throw new RegoValidationException(validationResult); } var setting = _repository.PaymentGatewaySettings .SingleOrDefault(x => x.Id == model.Id); if (setting == null) { throw new RegoException(string.Format("Payment gateway settings with id '{0}' were not found", model.Id)); } setting.OnlinePaymentMethodName = model.OnlinePaymentMethodName; setting.PaymentGatewayName = model.PaymentGatewayName; setting.Channel = model.Channel; setting.EntryPoint = model.EntryPoint; setting.Remarks = model.Remarks; setting.DateUpdated = _paymentQueries.GetBrandDateTimeOffset(model.Brand); setting.UpdatedBy = _actorInfoProvider.Actor.UserName; using (var scope = CustomTransactionScope.GetTransactionScope()) { _repository.SaveChanges(); _eventBus.Publish(new PaymentGatewaySettingUpdated { Id = setting.Id, UpdatedBy = setting.UpdatedBy, UpdatedDate = setting.DateUpdated.GetValueOrDefault(), OnlinePaymentMethodName = setting.OnlinePaymentMethodName, PaymentGatewayName = setting.PaymentGatewayName, Channel = setting.Channel, EntryPoint = setting.EntryPoint, BrandId = setting.BrandId }); scope.Complete(); } return(new SavePaymentGatewaysSettingsResult { PaymentGatewaySettingsId = setting.Id }); }
public ValidationResult ValidateThatPaymentGatewaySettingsCanBeEdited(SavePaymentGatewaysSettingsData model) { var validator = new SavePaymentGatewaySettingsValidator(_repository, false); return(validator.Validate(model)); }