public ActionResult <SettingDto> PostSettings(SettingDto settingDto)
        {
            settingDto = _service.Add(settingDto);
            _service.Save();

            return(settingDto);
        }
Beispiel #2
0
        public async Task <ActionResult> CreateUpdate(SettingType type, [FromBody] SettingDto mealDto)
        {
            mealDto.Type = type;
            await _settingsService.CreateUpdateAsync(mealDto);

            return(NoContent());
        }
Beispiel #3
0
        public SettingDto Add(SettingDto item)
        {
            Setting setting = MapperHelper <Setting, SettingDto> .ConvertToModel(item);

            SettingDto settingDto = MapperHelper <Setting, SettingDto> .ConvertToDto(_repository.Add(setting));

            return(settingDto);
        }
Beispiel #4
0
        private void SaveSettingsHandler()
        {
            try
            {
                if (_appEnvironment.ServiceConnector == null)
                {
                    throw new NullReferenceException($"Null reference of { nameof(_appEnvironment.ServiceConnector) }");
                }

                var settingDto = new SettingDto()
                {
                    ProfileId             = SessionStorage.Instance.ProfileId,
                    NotificationNeedStart = NeedBeginNotify,
                    EnablePopupNotify     = EnablePopupNotify,
                    EnableSoundNotify     = EnableSoundNotify,
                    ActivityCategories    = _categories,
                    TrackedSites          = _trackedSites
                };

                var response = _appEnvironment.ServiceConnector.Post <SettingDto, SuccessMsgDto, ErrorMsgDto>(new Request <SettingDto>
                {
                    AuthToken   = new KeyValuePair <string, string>("session_token", SessionStorage.Instance.SessionId),
                    UrlSegments = new Dictionary <string, string>()
                    {
                        { "id", SessionStorage.Instance.ProfileId }
                    },
                    Body   = settingDto,
                    OpName = OperationType.UpdateSettings,
                });

                if (response.SuccessBody != null)
                {
                }
            }
            catch (ApplicationException e)
            {
                Logger.Log.Debug(e.Message);
            }
            catch (Exception e)
            {
                Logger.Log.Debug(e.Message);
            }
            finally
            {
                if (IsDirty)
                {
                    AcceptChanges();
                    _appEnvironment.EventHub.Publish <ChangeSettingsMessage>(new ChangeSettingsMessage()
                    {
                        NeedBegin       = NeedBeginNotify,
                        NeedPopupNotify = EnablePopupNotify,
                        NeedSoundNotify = EnableSoundNotify,
                        Categories      = _categories
                    });
                }
            }
        }
Beispiel #5
0
        private async Task EditSetting(SettingDto dto)
        {
            var ent = await _dbCtx.Settings.FindAsync(dto.Id);

            if (ent != null)
            {
                ent.Value = dto.Value;
                _dbCtx.Settings.Update(ent);
            }
        }
Beispiel #6
0
        public IActionResult GetAll()
        {
            var obj = UnitOfWork.SettingRepository.GetAll().FirstOrDefault();
            var dto = new SettingDto();

            if (obj != null)
            {
                dto.SaveTo(obj);
            }
            return(Ok(dto));
        }
        public async Task <ActionResult> PutSetting(SettingKey key, [FromBody] SettingDto settingDto)
        {
            if (key != settingDto.Key)
            {
                return(BadRequest());
            }

            await _settingsService.SetSettingValueAsync(key, settingDto);

            return(NoContent());
        }
        public WarehousingRepository(DatabaseContext context, UserManager <UserEntity> userManager,
                                     IHttpContextAccessor httpContextAccessor) : base(context)
        {
            _context             = context;
            _entity              = _context.Set <WarehousingEntity>();
            _userManager         = userManager;
            _httpContextAccessor = httpContextAccessor;

            var settings = _context.Settings.ToArray();

            setting = Mapper.Map <SettingDto>(settings[0]);
        }
Beispiel #9
0
        public SettingDto Get()
        {
            var setting = new SettingDto
            {
                DefaultPasswordComplexity = GetDefaultPasswordComplexitySetting(),
                PasswordComplexity        = GetPasswordComplexitySetting(),
                UserLockOut    = GetUserLockOutSetting(),
                UserManagement = GetUserManagementSetting()
            };

            return(setting);
        }
Beispiel #10
0
 public async Task Update(SettingDto input)
 {
     if (StudioXSession.TenantId != null)
     {
         var tenantId = StudioXSession.TenantId.Value;
         await UpdateTenantSetting(tenantId, input);
     }
     else
     {
         await UpdateApplicationSetting(input);
     }
 }
Beispiel #11
0
        /// <inheritdoc />
        public virtual ISettingDto AddSetting(CreateSettingInput input)
        {
            var setting = new SettingDto
            {
                Key         = input.Key,
                Value       = input.Value,
                Description = input.Description,
                DataType    = input.DataType,
            };

            Settings.Add(setting);
            return(setting);
        }
        public async Task PutSetting_NoExceptionsWasThrown_ReturnNoContentResult()
        {
            var settingKey = SettingKey.RequestAutoCancelTimespan;
            var settingDto = new SettingDto {
                Key = settingKey
            };

            var result = await _controller.PutSetting(settingKey, settingDto);

            result
            .Should()
            .BeOfType <NoContentResult>();
        }
Beispiel #13
0
 public async Task <ActionResult> Delete(int id, SettingDto setting)
 {
     try
     {
         await _settingService.Delete(id);
     }
     catch (CustomException e)
     {
         ModelState.AddModelError(e.HttpCode.ToString(), e.CustomMessage);
         return(View());
     }
     return(RedirectToAction(nameof(Index)));
 }
        public async Task PutSetting_IdInSettingDtoDoesNotEqualToIdInRoute_ReturnsBadRequestResult()
        {
            var settingKey = SettingKey.RequestAutoCancelRemindTimespan;
            var settingDto = new SettingDto {
                Key = SettingKey.RequestAutoCancelTimespan
            };

            var result = await _controller.PutSetting(settingKey, settingDto);

            result
            .Should()
            .BeOfType <BadRequestResult>();
        }
Beispiel #15
0
        /// <inheritdoc />
        public virtual ISettingDto UpdateSetting(UpdateSettingInput input)
        {
            var setting = GetSettingInternal(input.Key);

            if (setting == null)
            {
                setting = new SettingDto
                {
                    Key = input.Key,
                };
                Settings.Add(setting);
            }
            input.ApplyTo(setting);
            return(setting);
        }
Beispiel #16
0
        /// <inheritdoc />
        public async Task CreateUpdateAsync(SettingDto settingDto)
        {
            SettingEntity settingEntity = await _settingsRepository.GetByTypeAsync(settingDto.Type);

            if (settingEntity == null)
            {
                settingEntity = _mapper.Map <SettingEntity>(settingDto);
                await _settingsRepository.CreateAsync(settingEntity);
            }
            else
            {
                _mapper.Map(settingDto, settingEntity);
                await _settingsRepository.UpdateAsync(settingEntity);
            }
        }
Beispiel #17
0
        public static SettingDto ToDto(this Setting e)
        {
            if (e == null)
            {
                return(null);
            }

            var res = new SettingDto();

            res.Id       = e.Id;
            res.Key      = e.Key;
            res.Type     = e.Type;
            res.Value    = e.Value;
            res.Required = e.Required;
            return(res);
        }
Beispiel #18
0
        private async Task UpdateApplicationSetting(SettingDto input)
        {
            await SettingManager.ChangeSettingForApplicationAsync(
                StudioXZeroSettingNames.UserManagement.PasswordComplexity.RequiredLength,
                input.PasswordComplexity.RequiredLength.ToString());


            await SettingManager.ChangeSettingForApplicationAsync(
                StudioXZeroSettingNames.UserManagement.PasswordComplexity.RequireDigit,
                input.PasswordComplexity.RequireDigit.ToString().ToLower());

            await SettingManager.ChangeSettingForApplicationAsync(
                StudioXZeroSettingNames.UserManagement.PasswordComplexity.RequireLowercase,
                input.PasswordComplexity.RequireLowercase.ToString().ToLower());

            await SettingManager.ChangeSettingForApplicationAsync(
                StudioXZeroSettingNames.UserManagement.PasswordComplexity.RequireUppercase,
                input.PasswordComplexity.RequireUppercase.ToString().ToLower());

            await SettingManager.ChangeSettingForApplicationAsync(
                StudioXZeroSettingNames.UserManagement.PasswordComplexity.RequireNonAlphanumeric,
                input.PasswordComplexity.RequireNonAlphanumeric.ToString().ToLower());

            // UserManagementSetting
            await SettingManager.ChangeSettingForApplicationAsync(
                StudioXZeroSettingNames.UserManagement.IsNewRegisteredUserActiveByDefault,
                input.UserManagement.IsNewRegisteredUserActiveByDefault.ToString().ToLower());

            await SettingManager.ChangeSettingForApplicationAsync(
                StudioXZeroSettingNames.UserManagement.IsEmailConfirmationRequiredForLogin,
                input.UserManagement.IsEmailConfirmationRequiredForLogin.ToString());

            // UserLockOut
            await SettingManager.ChangeSettingForApplicationAsync(
                StudioXZeroSettingNames.UserManagement.UserLockOut.IsEnabled,
                input.UserLockOut.IsEnabled.ToString().ToLower());

            await SettingManager.ChangeSettingForApplicationAsync(
                StudioXZeroSettingNames.UserManagement.UserLockOut.DefaultAccountLockoutSeconds,
                input.UserLockOut.DefaultAccountLockoutSeconds.ToString());

            await SettingManager.ChangeSettingForApplicationAsync(
                StudioXZeroSettingNames.UserManagement.UserLockOut.MaxFailedAccessAttemptsBeforeLockout,
                input.UserLockOut.MaxFailedAccessAttemptsBeforeLockout.ToString());
        }
Beispiel #19
0
        public async Task <ActionResult> Create(SettingDto setting)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var created = await _settingService.Add(setting);
                }
                catch (CustomException e)
                {
                    ModelState.AddModelError(e.HttpCode.ToString(), e.CustomMessage);
                    return(View(setting));
                }

                return(RedirectToAction(nameof(Index)));
            }
            return(View(setting));
        }
Beispiel #20
0
 public void SaveSetting(SettingDto setting)
 {
     foreach (var type in _assembley.GetTypes())
     {
         if (type.Name == "Settings" && typeof(SettingsBase).IsAssignableFrom(type))
         {
             var defaults = (SettingsBase)type.GetProperty("Default").GetValue(null, null);
             foreach (SettingsProperty prop in defaults.Properties)
             {
                 if (prop.Name.Equals(setting.Key))
                 {
                     defaults[prop.Name] = setting.Value;
                     defaults.Save();
                 }
             }
         }
     }
 }
Beispiel #21
0
        public async Task <Setting> Update(SettingDto setting)
        {
            var findSetting = _uow.SettingsRepository.FirstOrDefaultAsync(x => x.Id == setting.Id).Result;

            if (findSetting == null)
            {
                _logger.LogError("A Setting with that Id was not found.");
                throw new SettingNotFound();
            }

            findSetting.Key   = setting.Key;
            findSetting.Value = setting.Value;

            _uow.SettingsRepository.Update(findSetting);
            await _uow.CommitAsync();

            return(findSetting);
        }
Beispiel #22
0
        private void MockData()
        {
            _setting = new Setting
            {
                Namespace   = "Timespans",
                Key         = SettingKey.RequestAutoCancelTimespan,
                Value       = "value",
                Description = "description"
            };

            _settingWithDefaultNamespace = new Setting
            {
                Namespace   = Setting.DefaultNamespace,
                Key         = SettingKey.RequestAutoCancelTimespan,
                Value       = "value1",
                Description = "description1"
            };

            _settingWithNullValue = new Setting
            {
                Namespace   = "Namespace",
                Key         = SettingKey.RequestAutoCancelTimespan,
                Value       = null,
                Description = "desc"
            };

            _defaultValueAttribute = new DefaultValueAttribute("defaultValue");
            _descriptionAttribute  = new DescriptionAttribute("description");
            _namespaceAttribute    = new NamespaceAttribute("namespace");

            _settingDto = new SettingDto
            {
                Key   = _setting.Key,
                Value = "new value"
            };

            _describedSettingDto = new DescribedSettingDto
            {
                Key          = _setting.Key,
                Value        = _setting.Value,
                Description  = _setting.Description,
                DefaultValue = _defaultValueAttribute.Value?.ToString()
            };
        }
Beispiel #23
0
        /// <inheritdoc />
        public virtual ISettingDto[] Initialize(ISettingDto[] systemSettings, string serviceVersion)
        {
            var cache = Settings.ToDictionary(s => s.Key);

            if (ApplicationIntentDeterminer.Repository == ApplicationIntent.ReadWrite)
            {
                var changed = false;

                // Handle missing settings
                var missingSettings = systemSettings.Where(s => !cache.ContainsKey(s.Key)).ToArray();
                if (missingSettings.Length > 0)
                {
                    foreach (var missingSetting in missingSettings)
                    {
                        var newSetting = new SettingDto
                        {
                            Key         = missingSetting.Key,
                            Value       = missingSetting.Value,
                            DataType    = missingSetting.DataType,
                            Description = missingSetting.Description,
                            IsSystem    = true
                        };
                        cache[missingSetting.Key] = newSetting;
                        Settings.Add(newSetting);
                    }

                    changed = true;
                }

                // Update service version
                if (cache.TryGetValue("ServiceVersion", out var versionSetting) && versionSetting.Value != serviceVersion)
                {
                    versionSetting.Value = serviceVersion;
                    changed = true;
                }

                if (changed)
                {
                    PersistChanges();
                }
            }

            return(cache.Values.ToArray <ISettingDto>());
        }
        public ActionResult <SettingDto> PutSetting(string id, SettingDto settingDto)
        {
            if (id != settingDto.Id)
            {
                return(BadRequest());
            }

            try
            {
                settingDto = _service.Edit(settingDto);
                _service.Save();
            }
            catch (Exception)
            {
                return(BadRequest());
            }

            return(settingDto);
        }
Beispiel #25
0
        public async Task <Setting> Add(SettingDto setting)
        {
            var findSetting = _uow.SettingsRepository.FirstOrDefaultAsync(x => x.Key == setting.Key).Result;

            if (findSetting != null)
            {
                _logger.LogError("A Setting with that Key already exist.");
                throw new KeyAlreadyExistException();
            }

            var newSetting = new Setting
            {
                Key   = setting.Key,
                Value = setting.Value
            };

            _uow.SettingsRepository.Add(newSetting);
            await _uow.CommitAsync();

            return(newSetting);
        }
        private static void EnsureRepositoryVersionIsCorrect(DefaultRepositoryProvider seedContext, InitializeArgs args)
        {
            var versionSetting = seedContext.Settings.FirstOrDefault(s => s.Key == "RepositoryVersion");

            if (versionSetting == null)
            {
                versionSetting          = new SettingDto();
                versionSetting.Key      = "RepositoryVersion";
                versionSetting.IsSystem = true;
                seedContext.Settings.Add(versionSetting);
            }

            var newVersion = args.SchemaVersion.ToString(CultureInfo.InvariantCulture);

            if (!Equals(versionSetting.Value, newVersion))
            {
                versionSetting.Value = newVersion;
            }

            seedContext.SaveChanges();
        }
        //TODO: need to save settings by user
        public void SaveSettingDto(SettingDto settingDto)
        {
            if (settingDto == null)
            {
                throw new ArgumentNullException(nameof(settingDto));
            }

            var colorSerialized          = _serializationService.SerializeObject(settingDto.AltRowsColor);
            var dateTimeFormatSerialized = _serializationService.SerializeObject(settingDto.DateFormateId);
            var pageSizeSerialized       = _serializationService.SerializeObject(settingDto.PageSize);

            var settingNames = new Dictionary <SettingNames, string>(2);

            settingNames.Add(SettingNames.DateTimeFormat, dateTimeFormatSerialized);
            settingNames.Add(SettingNames.AltRowsColor, colorSerialized);
            settingNames.Add(SettingNames.PageSize, pageSizeSerialized);

            _settingProvider.SaveSettings(settingNames);

            _applicationCasheService.RemoveValue(ApplicationCasheNames.SettingDto);
        }
Beispiel #28
0
 public IActionResult Set(SettingDto dto)
 {
     try
     {
         var obj = UnitOfWork.SettingRepository.GetAll().FirstOrDefault();
         if (obj == null)
         {
             var entity = dto.LoadFrom();
             UnitOfWork.SettingRepository.Add(entity);
         }
         else
         {
             dto.CheckChanges(obj);
         }
         UnitOfWork.Complete();
         return(Ok());
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.Message));
     }
 }
        public IActionResult SetttingPageLevel(SettingDto objsetting)
        {
            var data = _settingService.GetSingle(x => x.Title == objsetting.Title && x.IsDelete == false && x.IsActive == true);

            if (data == null)
            {
                if (objsetting.Id == 0)
                {
                    return(base.View(@"Components/_AddSetting", new SettingDto {
                        Id = objsetting.Id, Title = objsetting.Title
                    }));
                }
            }
            var dto = new SettingDto()
            {
                Id    = data.Id,
                Title = data.Title,
                Html  = data.Html
            };

            return(View(@"Components/_AddSetting", dto));
        }
Beispiel #30
0
        public void Update(SettingDto input)
        {
            CheckToken();
            string  contentPath = _hostingEnvironment.ContentRootPath + @"\";
            var     filePath    = contentPath + "appsettings.json";
            JObject jsonObject;

            using (StreamReader file = new StreamReader(filePath))
                using (JsonTextReader reader = new JsonTextReader(file))
                {
                    jsonObject = (JObject)JToken.ReadFrom(reader);
                    if (input.CORSRule != null)
                    {
                        jsonObject["App"]["CorsOrigins"]         = string.Join(',', input.CORSRule.AllowedOrigins);
                        jsonObject["App"]["CorsHeaders"]         = string.Join(',', input.CORSRule.AllowedHeaders);
                        jsonObject["App"]["CorsMethods"]         = string.Join(',', input.CORSRule.AllowedMethods);
                        jsonObject["App"]["CorsPreflightMaxAge"] = input.CORSRule.MaxAgeSeconds + "";
                    }
                    if (input.RefererRule != null)
                    {
                        jsonObject["App"]["RefererCanNull"] = input.RefererRule.AllowEmptyReferer.ToString();
                        jsonObject["App"]["Referers"]       = string.Join(',', input.RefererRule.RefererList);
                    }
                }

            using (var writer = new StreamWriter(filePath))
                using (JsonTextWriter jsonwriter = new JsonTextWriter(writer))
                {
                    jsonwriter.Formatting  = Formatting.Indented;
                    jsonwriter.IndentChar  = ' ';
                    jsonwriter.Indentation = 2;

                    JsonSerializer serializer = new JsonSerializer();
                    serializer.Serialize(jsonwriter, jsonObject);
                }

            _applicationLifetime.StopApplication();
        }