Example #1
0
        private void SaveConfigurationChanges(Dictionary <string, string> appSettings)
        {
            var oldSettings = _serverSettings.ServerData.GetType().GetAllProperties()
                              .ToDictionary(s => s.Key, s => _serverSettings.ServerData.GetNestedPropertyValue(s.Key).ToNullSafeString());
            var oldValues = new Dictionary <string, string>();
            var newValues = new Dictionary <string, string>();

            foreach (var oldSetting in oldSettings)
            {
                if (appSettings.ContainsKey(oldSetting.Key))
                {
                    var newValue = appSettings[oldSetting.Key].ToLowerInvariant();

                    //Special case for nullable bool
                    if (newValue == "null")
                    {
                        newValue = string.Empty;
                    }
                    var oldValue = oldSetting.Value != null?oldSetting.Value.ToLowerInvariant() : string.Empty;

                    if (oldValue != newValue)
                    {
                        oldValues.Add(oldSetting.Key, oldSetting.Value);
                        newValues.Add(oldSetting.Key, appSettings[oldSetting.Key]);
                    }
                }
            }

            _configurationChangeService.Add(oldValues,
                                            newValues,
                                            ConfigurationChangeType.CompanySettings,
                                            new Guid(AuthSession.UserAuthId),
                                            AuthSession.UserAuthName);
        }
Example #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);
        }