| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Linq; |
| | | 4 | | using SVETA.Api.Data.DTO; |
| | | 5 | | using System.Threading.Tasks; |
| | | 6 | | using WinSolutions.Sveta.Server.Data.DataModel.Entities; |
| | | 7 | | |
| | | 8 | | namespace SVETA.Api.Data.Domain |
| | | 9 | | { |
| | | 10 | | public class ConfigurationsSettings |
| | | 11 | | { |
| | 0 | 12 | | public ICollection<ConfigurationResponseDTO> AppConfs { get; set; } = new List<ConfigurationResponseDTO>(); |
| | | 13 | | public string GetConfValue(string section, string key) |
| | 0 | 14 | | { |
| | 0 | 15 | | var value = AppConfs.FirstOrDefault(x => x.Section == section && x.Key == key)?.Value; |
| | 0 | 16 | | if (string.IsNullOrWhiteSpace(value)) |
| | 0 | 17 | | throw new ArgumentException($"Не указан ключ {key} для секции {section}"); |
| | 0 | 18 | | return value; |
| | 0 | 19 | | } |
| | | 20 | | public void SetConfValue(string section, string key, string value) |
| | 0 | 21 | | { |
| | 0 | 22 | | if (!AppConfs.Any(x => x.Section == section && x.Key == key)) |
| | 0 | 23 | | throw new ArgumentException($"Не найдено записей конфигурации с ключом {key} и секцией {section}"); |
| | 0 | 24 | | if (string.IsNullOrWhiteSpace(value)) |
| | 0 | 25 | | throw new ArgumentException($"Не указано значение для ключа {key}"); |
| | 0 | 26 | | AppConfs.FirstOrDefault(x => x.Section == section && x.Key == key).Value = value; |
| | 0 | 27 | | } |
| | | 28 | | } |
| | | 29 | | } |