Example #1
0
        public BasicResponse <SettingInfo> AddSetting(SettingAddRequest settingrequest)
        {
            var _setting        = ObjectConverter.Copy <SettingInfo, SettingModel>(settingrequest.SettingInfo);
            var resultsetting   = _Repository.AddSetting(_setting);
            var settingresponse = new BasicResponse <SettingInfo>();

            settingresponse.Data = ObjectConverter.Copy <SettingModel, SettingInfo>(resultsetting);
            return(settingresponse);
        }
Example #2
0
        /// <summary>
        ///保存配置文件到数据库
        /// </summary>
        /// <param name="alarmRequest"></param>
        /// <returns></returns>
        public BasicResponse <bool> SaveConfigToDatabase(SaveConfigToDatabaseRequest alarmRequest)
        {
            var response = new BasicResponse <bool>();

            try
            {
                if (alarmRequest.SettingInfo == null)
                {
                    var settingModel = new SettingModel();
                    settingModel.StrType        = "报警配置";
                    settingModel.StrKey         = "AlarmShowConfig";
                    settingModel.StrKeyCHs      = "报警设置";
                    settingModel.StrValue       = alarmRequest.Config;
                    settingModel.LastUpdateDate = DateTime.Now.ToString();
                    _SettingRepository.AddSetting(settingModel);
                }
                else
                {
                    var settingModel = _SettingRepository.GetSettingById(alarmRequest.SettingInfo.ID);
                    settingModel.StrValue       = alarmRequest.Config;
                    settingModel.LastUpdateDate = DateTime.Now.ToString();
                    _SettingRepository.UpdateSetting(settingModel);
                }
                response.Data = true;
            }
            catch (Exception ex)
            {
                response.Data    = false;
                response.Code    = -100;
                response.Message = ex.Message;
                this.ThrowException("SaveConfigToDatabase-保存配置文件到数据库-发生异常 ", ex);
            }

            return(response);
        }
Example #3
0
        public void UpdateSetting(string entityName, int entityId, string settingName, string settingValue)
        {
            var update = _settingRepository
                         .GetSettings(entityName, entityId)
                         .FirstOrDefault(item => item.SettingName == settingName);

            if (update != null)
            {
                update.SettingValue = settingValue;
                update.ModifiedOn   = DateTime.Now;
                update.ModifiedBy   = WipConstants.SettingsChangeUserId;
                _settingRepository.UpdateSetting(update);
            }
            else
            {
                _settingRepository.AddSetting(new Setting
                {
                    CreatedBy    = WipConstants.SettingsChangeUserId,
                    CreatedOn    = DateTime.Now,
                    EntityName   = EntityNames.Module,
                    EntityId     = entityId,
                    ModifiedOn   = DateTime.Now,
                    ModifiedBy   = WipConstants.SettingsChangeUserId,
                    SettingName  = settingName,
                    SettingValue = settingValue
                });
            }
        }
Example #4
0
        public override int GetZoneId(int tenantId)
        {
            // additional protection against invalid portalId which may come from bad dnn configs and execute in search-index mode
            // see https://github.com/2sic/2sxc/issues/1054
            if (tenantId < 0)
            {
                throw new Exception("Can't get zone for invalid portal ID: " + tenantId);
            }

            if (HasZoneId(tenantId, out var i))
            {
                return(i);
            }

            // Create new zone automatically
            var portalSettings = _siteRepository.GetSite(tenantId);
            var zoneId         = _zoneCreatorLazy.Value.Init(Log).Create(portalSettings.Name + " (Site " + tenantId + ")");

            _settingRepository.AddSetting(new Setting
            {
                CreatedBy    = "2sxc",
                CreatedOn    = DateTime.Now,
                EntityId     = tenantId,
                EntityName   = EntityNames.Site,
                ModifiedBy   = "2sxc",
                ModifiedOn   = DateTime.Now,
                SettingName  = OqtConstants.SiteKeyForZoneId,
                SettingValue = zoneId.ToString()
            });
            return(zoneId);
        }
Example #5
0
 public Setting Post([FromBody] Setting Setting)
 {
     if (ModelState.IsValid && IsAuthorized(Setting.EntityName, Setting.EntityId))
     {
         Setting = Settings.AddSetting(Setting);
     }
     return(Setting);
 }
Example #6
0
 public Setting Post([FromBody] Setting Setting)
 {
     if (ModelState.IsValid)
     {
         Setting = Settings.AddSetting(Setting);
     }
     return(Setting);
 }
Example #7
0
 public Setting Post([FromBody] Setting Setting)
 {
     if (ModelState.IsValid && IsAuthorized(Setting.EntityName, Setting.EntityId))
     {
         Setting = Settings.AddSetting(Setting);
         logger.Log(LogLevel.Information, this, LogFunction.Create, "Setting Added {Setting}", Setting);
     }
     return(Setting);
 }
Example #8
0
 public Setting Post([FromBody] Setting Setting)
 {
     if (ModelState.IsValid && IsAuthorized(Setting.EntityName, Setting.EntityId, "Edit"))
     {
         Setting = _settings.AddSetting(Setting);
         _logger.Log(LogLevel.Information, this, LogFunction.Create, "Setting Added {Setting}", Setting);
     }
     else
     {
         _logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add Setting {Setting}", Setting);
         HttpContext.Response.StatusCode = 401;
         Setting = null;
     }
     return(Setting);
 }
Example #9
0
 public Setting Post([FromBody] Setting setting)
 {
     if (ModelState.IsValid && IsAuthorized(setting.EntityName, setting.EntityId, PermissionNames.Edit))
     {
         setting = _settings.AddSetting(setting);
         AddSyncEvent(setting.EntityName);
         _logger.Log(LogLevel.Information, this, LogFunction.Create, "Setting Added {Setting}", setting);
     }
     else
     {
         _logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add Setting {Setting}", setting);
         HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
         setting = null;
     }
     return(setting);
 }
 public Setting Post([FromBody] Setting setting)
 {
     if (ModelState.IsValid && IsAuthorized(setting.EntityName, setting.EntityId, PermissionNames.Edit))
     {
         setting = _settings.AddSetting(setting);
         if (setting.EntityName == EntityNames.Module)
         {
             _syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, _alias.SiteId);
         }
         _logger.Log(LogLevel.Information, this, LogFunction.Create, "Setting Added {Setting}", setting);
     }
     else
     {
         _logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add Setting {Setting}", setting);
         HttpContext.Response.StatusCode = 401;
         setting = null;
     }
     return(setting);
 }