예제 #1
0
        public async Task SetValueAsync(GlobalConfigItems key, string data)
        {
            Configuration[key.ToString()] = data;

            using var scope      = ServiceProvider.CreateScope();
            using var repository = scope.ServiceProvider.GetService <IGrillBotRepository>();

            var item = await repository.GlobalConfigRepository.GetItemAsync(key);

            if (item == null)
            {
                item = new GlobalConfigItem()
                {
                    Key   = key.ToString(),
                    Value = data
                };

                await repository.AddAsync(item);
            }
            else
            {
                item.Value = data;
            }

            await repository.CommitAsync();
        }
예제 #2
0
        public async Task <string> GetItemAsync(GlobalConfigItems itemKey)
        {
            var key    = itemKey.ToString();
            var result = await Context.GlobalConfig
                         .SingleOrDefaultAsync(o => o.Key == key);

            return(result?.Value);
        }
예제 #3
0
        public async Task UpdateItemAsync(GlobalConfigItems item, string value)
        {
            var key = item.ToString();

            var result = await Context.GlobalConfig
                         .SingleOrDefaultAsync(o => o.Key == key);

            if (result == null)
            {
                result = new GlobalConfigItem()
                {
                    Key   = key,
                    Value = value
                };

                Context.GlobalConfig.Add(result);
            }
            else
            {
                result.Value = value;
            }

            await Context.SaveChangesAsync();
        }
예제 #4
0
 public Task <GlobalConfigItem> GetItemAsync(GlobalConfigItems key)
 {
     return(Context.GlobalConfig.AsQueryable()
            .SingleOrDefaultAsync(o => o.Key == key.ToString()));
 }
예제 #5
0
 public string GetValue(GlobalConfigItems key)
 {
     return(Configuration[key.ToString()]);
 }