Ejemplo n.º 1
0
        public IActionResult GetSettings(string key)
        {
            var settings = settingsRepository.GetSettings(CurrentUserId, key);

            if (settings == null)
            {
                settings = SettingsUtils.CreateDefault(key);
            }
            return(Ok(settings));
        }
Ejemplo n.º 2
0
        public IActionResult UpdateSettings([FromBody] SettingsRequest request)
        {
            var type = typeof(SettingsKeyAttribute).Assembly.GetTypes().FirstOrDefault(t => t.GetCustomAttribute <SettingsKeyAttribute>()?.Key == request.Key);

            if (type == null)
            {
                return(BadRequest("Unknown key"));
            }

            var settings = settingsRepository.GetSettings(CurrentUserId, request.Key);

            if (settings == null)
            {
                settings = SettingsUtils.CreateDefault(request.Key);
            }

            SettingsUtils.Merge(settings, request.Data);

            settingsRepository.UpdateSettings(CurrentUserId, request.Key, settings);

            return(Ok());
        }