Exemple #1
0
        public async Task <IActionResult> DeleteOverride(OverrideValueModel model)
        {
            try
            {
                var keyValue = await _keyValuesRepository.GetKeyValueAsync(model.Key);

                var list = keyValue.Override?.ToList();

                var overrideValue = list?.FirstOrDefault(item => item.NetworkId == model.NetworkId);

                if (overrideValue != null)
                {
                    list.Remove(overrideValue);
                    keyValue.Override = list.ToArray();
                    await _keyValuesRepository.UpdateKeyValueAsync(new[] { keyValue });
                }

                await AddToHistoryAsync(keyValue);

                return(JsonRequestResult("#overrideValues", Url.Action("List"), false, new { key = model.Key }));
            }
            catch (Exception ex)
            {
                _log.Error(ex, context: model);
                return(JsonRequestResult("#overrideValues", Url.Action("List"), false, new { key = String.Empty }));
            }
        }
Exemple #2
0
        public async Task <IActionResult> UpdateOverride(OverrideValueModel model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.Value))
                {
                    return(JsonErrorValidationResult("Value is required", $"#{model.NetworkId}"));
                }

                var keyValue = await _keyValuesRepository.GetKeyValueAsync(model.Key);

                var existingValue = keyValue.Override?.FirstOrDefault(item => item.NetworkId == model.NetworkId);

                if (existingValue != null)
                {
                    existingValue.Value = model.Value;
                }

                await _keyValuesRepository.UpdateKeyValueAsync(new[] { keyValue });

                await AddToHistoryAsync(keyValue);

                return(JsonRequestResult("#overrideValues", Url.Action("List"), false, new { key = model.Key }));
            }
            catch (Exception ex)
            {
                _log.Error(ex, context: model);
                return(JsonRequestResult("#overrideValues", Url.Action("List"), false, new { key = String.Empty }));
            }
        }
Exemple #3
0
        public async Task <IActionResult> AddOverride(OverrideValueModel model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.Value))
                {
                    return(JsonErrorValidationResult("Value is required", "#override_value"));
                }

                var overrideValue = new OverrideValue
                {
                    NetworkId = model.NetworkId,
                    Value     = model.Value
                };

                var keyValue = await _keyValuesRepository.GetKeyValueAsync(model.Key);

                if (keyValue.Override == null)
                {
                    keyValue.Override = new[] { overrideValue }
                }
                ;
                else
                {
                    var list = keyValue.Override.ToList();
                    list.Add(overrideValue);
                    keyValue.Override = list.ToArray();
                }

                await _keyValuesRepository.UpdateKeyValueAsync(new[] { keyValue });

                await AddToHistoryAsync(keyValue);

                return(JsonRequestResult("#overrideValues", Url.Action("List"), false, new { key = model.Key }));
            }
            catch (Exception ex)
            {
                _log.Error(ex, context: model);
                return(JsonRequestResult("#overrideValues", Url.Action("List"), false, new { key = String.Empty }));
            }
        }