Пример #1
0
        private static KeyValuePair <string, string> ExtractPropertyValue(ServerPaymentSettings paymentSettings, string propertyName)
        {
            var settingValue       = paymentSettings.GetNestedPropertyValue(propertyName);
            var settingStringValue = settingValue.SelectOrDefault(value => value.ToString(), string.Empty);


            settingStringValue = settingStringValue.IsBool()
                ? settingStringValue.ToLowerInvariant()
                : settingStringValue;

            return(new KeyValuePair <string, string>(propertyName, settingStringValue));
        }
Пример #2
0
        private void SaveConfigurationChanges(ServerPaymentSettings newSettings, ServerPaymentSettings oldSettings)
        {
            var oldSettingsDictionary = oldSettings.GetType().GetAllProperties()
                                        .ToDictionary(s => s.Key, s => oldSettings.GetNestedPropertyValue(s.Key).ToNullSafeString());
            var newSettingsDictionary = newSettings.GetType().GetAllProperties()
                                        .ToDictionary(s => s.Key, s => newSettings.GetNestedPropertyValue(s.Key).ToNullSafeString());

            var oldValues = new Dictionary <string, string>();
            var newValues = new Dictionary <string, string>();

            foreach (var oldSetting in oldSettingsDictionary)
            {
                if (newSettingsDictionary.ContainsKey(oldSetting.Key))
                {
                    var newValue = newSettingsDictionary[oldSetting.Key];

                    if (oldSetting.Value != newValue)
                    {
                        //Special case for Amounts if not formatted the same way
                        double oldAmount;
                        double newAmount;
                        double.TryParse(oldSetting.Value, out oldAmount);
                        double.TryParse(newValue, out newAmount);
                        if ((oldAmount == 0 && newAmount == 0) || Math.Abs(oldAmount - newAmount) > 0)
                        {
                            oldValues.Add(oldSetting.Key, oldSetting.Value);
                            newValues.Add(oldSetting.Key, newSettingsDictionary[oldSetting.Key]);
                        }
                    }
                }
            }

            var authSession = this.GetSession();

            _configurationChangeService.Add(oldValues,
                                            newValues,
                                            ConfigurationChangeType.PaymentSetttings,
                                            new Guid(authSession.UserAuthId),
                                            authSession.UserAuthName);
        }