public void UpdateSettings(SaveTransferSettingsCommand model)
        {
            var validationResult = new SaveTransferSettingsValidator().Validate(model);

            if (!validationResult.IsValid)
            {
                throw new RegoException(validationResult.Errors.First().ErrorMessage);
            }

            var transferSettings = _repository.TransferSettings.SingleOrDefault(x => x.Id == model.Id);

            if (transferSettings == null)
            {
                throw new RegoException(string.Format("Unable to find Transfer Settings with Id '{0}'", model.Id));
            }

            transferSettings.MinAmountPerTransaction = model.MinAmountPerTransaction;
            transferSettings.MaxAmountPerTransaction = model.MaxAmountPerTransaction;
            transferSettings.MaxAmountPerDay         = model.MaxAmountPerDay;
            transferSettings.MaxTransactionPerDay    = model.MaxTransactionPerDay;
            transferSettings.MaxTransactionPerWeek   = model.MaxTransactionPerWeek;
            transferSettings.MaxTransactionPerMonth  = model.MaxTransactionPerMonth;
            transferSettings.UpdatedDate             = DateTimeOffset.Now.ToBrandOffset(model.TimezoneId);
            transferSettings.UpdatedBy = _actorInfoProvider.Actor.UserName;
            _repository.SaveChanges();

            _eventBus.Publish(new TransferFundSettingsUpdated
            {
                TransferSettingsId = transferSettings.Id,
                UpdatedBy          = transferSettings.UpdatedBy,
                Updated            = transferSettings.UpdatedDate
            });
        }
        public Guid AddSettings(SaveTransferSettingsCommand model)
        {
            var validationResult = new SaveTransferSettingsValidator().Validate(model);

            if (!validationResult.IsValid)
            {
                throw new RegoException(validationResult.Errors.First().ErrorMessage);
            }

            if (_repository.TransferSettings.Any(x => x.Id == model.Id))
            {
                throw new RegoException(TransferFundSettingsErrors.AlreadyExistsError.ToString());
            }

            if (_repository.TransferSettings.Any(
                    x => x.BrandId == model.Brand &&
                    x.VipLevelId == model.VipLevel &&
                    x.TransferType == model.TransferType &&
                    x.CurrencyCode == model.Currency &&
                    x.WalletId == model.Wallet))
            {
                throw new RegoException(TransferFundSettingsErrors.AlreadyExistsError.ToString());
            }

            var transferSettings = new AFT.RegoV2.Core.Payment.Data.TransferSettings();

            transferSettings.Id                      = model.Id == Guid.Empty ? Guid.NewGuid() : model.Id;
            transferSettings.BrandId                 = model.Brand;
            transferSettings.CurrencyCode            = model.Currency;
            transferSettings.VipLevelId              = model.VipLevel;
            transferSettings.TransferType            = model.TransferType;
            transferSettings.WalletId                = model.Wallet;
            transferSettings.CreatedDate             = DateTimeOffset.Now.ToBrandOffset(model.TimezoneId);
            transferSettings.CreatedBy               = _actorInfoProvider.Actor.UserName;
            transferSettings.MinAmountPerTransaction = model.MinAmountPerTransaction;
            transferSettings.MaxAmountPerTransaction = model.MaxAmountPerTransaction;
            transferSettings.MaxAmountPerDay         = model.MaxAmountPerDay;
            transferSettings.MaxTransactionPerDay    = model.MaxTransactionPerDay;
            transferSettings.MaxTransactionPerWeek   = model.MaxTransactionPerWeek;
            transferSettings.MaxTransactionPerMonth  = model.MaxTransactionPerMonth;
            _repository.TransferSettings.Add(transferSettings);
            _repository.SaveChanges();

            _eventBus.Publish(new TransferFundSettingsCreated
            {
                TransferSettingsId = transferSettings.Id,
                CreatedBy          = transferSettings.CreatedBy,
                Created            = transferSettings.CreatedDate
            });

            return(transferSettings.Id);
        }