示例#1
0
        private List <UpdateSettingsViewModel> GetSettingsPrivate(int?incDisabled)
        {
            List <SystemSetting> _settings = new List <SystemSetting>();

            using (DBManager db = new DBManager())
            {
                if (incDisabled != null && incDisabled == 1)
                {
                    _settings = db.getConnection().GetList <SystemSetting>().ToList();
                }
                else
                {
                    _settings = db.getConnection().GetList <SystemSetting>(new { IsActive = 1 }).ToList();
                }
            }

            List <UpdateSettingsViewModel> _editSettings = new List <UpdateSettingsViewModel>();

            foreach (SystemSetting _item in _settings)
            {
                var _vm = new UpdateSettingsViewModel();
                _vm.PopulateVM(_item);
                _editSettings.Add(_vm);
            }

            return(_editSettings);
        }
示例#2
0
        public bool Update(UpdateSettingsViewModel viewModel)
        {
            if (viewModel.ClientIdleTimeout < 0 ||
                viewModel.ReceiveTimeout < 0 ||
                viewModel.SendTimeout < 0)
            {
                return(false);
            }

            List <IPAddress> relayingIps = new List <IPAddress>();

            foreach (string str in viewModel.IpAddressesForRelaying)
            {
                relayingIps.Add(IPAddress.Parse(str));
            }

            CfgPara.SetClientIdleTimeout(viewModel.ClientIdleTimeout);
            CfgPara.SetReceiveTimeout(viewModel.ReceiveTimeout);
            CfgPara.SetSendTimeout(viewModel.SendTimeout);
            CfgPara.SetDefaultVirtualMtaGroupID(viewModel.DefaultVirtualMtaGroupID);
            CfgPara.SetEventForwardingHttpPostUrl(viewModel.EventUrl);
            CfgPara.SetDaysToKeepSmtpLogsFor(viewModel.DaysToKeepSmtpLogsFor);
            CfgPara.SetMaxTimeInQueueMinutes(viewModel.MaxTimeInQueueHours * 60);
            CfgPara.SetRetryIntervalBaseMinutes(viewModel.RetryIntervalBase);
            CfgRelayingPermittedIP.SetRelayingPermittedIPAddresses(relayingIps.ToArray());
            CfgPara.SetReturnPathLocalDomain(viewModel.ReturnPathLocalDomainID);

            var domains = CfgLocalDomains.GetLocalDomainsArray();

            CfgLocalDomains.ClearLocalDomains();
            foreach (string localDomain in viewModel.LocalDomains)
            {
                if (string.IsNullOrWhiteSpace(localDomain))
                {
                    continue;
                }
                LocalDomain ld = domains.SingleOrDefault(d => d.Hostname.Equals(localDomain, StringComparison.OrdinalIgnoreCase));
                if (ld == null)
                {
                    ld = new LocalDomain {
                        Hostname = localDomain.Trim()
                    }
                }
                ;
                CfgLocalDomains.Save(ld);
            }

            return(true);
        }
    }
示例#3
0
        public void UpdateSettings()
        {
            var vm = new UpdateSettingsViewModel(settingsRepository);

            if (ShowDialog(vm))
            {
                var sOld = vm.GetOldSettingsInfo();
                var sNew = vm.GetNewSettingsInfo();

                settingsRepository.UpdateSettings(sNew);

                logger.Log(string.Format(Resources.LogUpdatedSettings, sOld.ToString("LOG", null), sNew.ToString("LOG", null)), Category.Debug, Priority.None);
            }
        }
示例#4
0
        public ActionResult SaveSettings(UpdateSettingsViewModel setting)
        {
            //https://stackoverflow.com/questions/13541225/asp-net-mvc-how-to-display-success-confirmation-message-after-server-side-proce

            if (setting == null)
            {
                ModelState.AddModelError(string.Empty, "Valid setting not found.");
            }

            if (ModelState.IsValid)
            {
                String _id = setting.Id;

                using (DBManager db = new DBManager())
                {
                    StringBuilder _sql = new StringBuilder();
                    _sql.Append($"Select * from SystemSettings where Id = '{_id}'");
                    SystemSetting _objToUpdate = db.getConnection().Query <SystemSetting>(_sql.ToString()).SingleOrDefault();
                    if (_objToUpdate == null)
                    {
                        ModelState.AddModelError(string.Empty, $"Setting [{_id.ToString()}] not found.  Please try again.");
                        return(JsonFormResponse());
                    }

                    if (TryUpdateModel <SystemSetting>(_objToUpdate))
                    {
                        try
                        {
                            _objToUpdate = UpdateAuditTracking(_objToUpdate);

                            _sql.Clear();
                            _sql.Append("Update SystemSettings set ");
                            _sql.Append($"UpdatedAt = '{_objToUpdate.UpdatedAt.FormatDatabaseDateTime()}'");
                            _sql.Append($",RowVersion = '{_objToUpdate.RowVersion.FormatDatabaseDateTime()}'");
                            _sql.Append($",UpdatedBy = '{_objToUpdate.UpdatedBy}'");
                            _sql.Append($",IsActive = {_objToUpdate.IsActive}");
                            _sql.Append($",SettingName = '{_objToUpdate.SettingName}'");
                            _sql.Append($",SettingValue = '{_objToUpdate.SettingValue}'");
                            _sql.Append($",CodeIdentifier = '{_objToUpdate.CodeIdentifier}'");
                            _sql.Append($" where Id = '{_objToUpdate.Id}'");
                            db.getConnection().Execute(_sql.ToString());

                            SystemSettings.Reset();

                            IAppCache cache = new CachingService();
                            cache.Remove("System_Settings_All");
                            cache.Remove("System_Settings_Active");

                            return(JsonSuccessResponse("Setting saved successfully", _objToUpdate));
                        }
                        //catch (DbUpdateConcurrencyException ex)
                        //{
                        //	var entry = ex.Entries.Single();
                        //	var clientValues = (SystemSetting)entry.Entity;
                        //	var databaseEntry = entry.GetDatabaseValues();
                        //	if (databaseEntry == null)
                        //	{
                        //		ModelState.AddModelError(string.Empty, "Unable to save changes. The system setting was deleted by another user.");
                        //	}
                        //	else
                        //	{
                        //		var databaseValues = (SystemSetting)databaseEntry.ToObject();

                        //		ModelState.AddModelError(string.Empty, "The record you attempted to edit "
                        //			+ "was modified by another user after you got the original value. The "
                        //			+ "edit operation was canceled and the current values in the database "
                        //			+ "have been displayed. If you still want to edit this record, click "
                        //			+ "the Save button again.");

                        //		if (databaseValues.SettingName != clientValues.SettingName)
                        //			ModelState.AddModelError("SettingName", "Current database value for setting name: " + databaseValues.SettingName);

                        //		if (databaseValues.SettingValue != clientValues.SettingValue)
                        //			ModelState.AddModelError("SettingValue", "Current database value for setting value: " + databaseValues.SettingValue);

                        //		if (databaseValues.CodeIdentifier != clientValues.CodeIdentifier)
                        //			ModelState.AddModelError("CodeIdentifier", "Current database value for code identifier: " + databaseValues.CodeIdentifier);
                        //	}
                        //}
                        catch (Exception ex)
                        {
                            ModelState.AddModelError(string.Empty, Helpers.FormatModelError("Error saving setting", ex));

                            LogHelper log = new LogHelper();
                            log.Log(LogHelper.LogLevels.Error, "Error saving setting", nameof(SaveSettings), ex, setting, Helpers.ParseValidationErrors(ex));
                        }
                    }
                }
            }

            if (!ModelState.IsValid)
            {
                Helpers.LogFormValidationErrors(ModelState, nameof(SaveSettings), setting);
            }

            return(JsonFormResponse());
        }