Exemplo n.º 1
0
    public async Task StoreAsync <T>(string key, T value)
    {
        if (string.IsNullOrEmpty(key))
        {
            throw new ArgumentException("Key MUST have a value");
        }
        using (var context = new GoogleAuthContext())
        {
            var    generatedKey = GenerateStoredKey(key, typeof(T));
            string json         = JsonConvert.SerializeObject(value);
            var    item         = await context.Items.SingleOrDefaultAsync(x => x.Key == generatedKey);

            if (item == null)
            {
                context.Items.Add(new Item {
                    Key = generatedKey, Value = json
                });
            }
            else
            {
                item.Value = json;
            }
            await context.SaveChangesAsync();
        }
    }
 public async Task StoreAsync <T>(string key, T value)
 {
     if (string.IsNullOrEmpty(key))
     {
         throw new ArgumentException("Key MUST have a value");
     }
     using (var context = new GoogleAuthContext())
     {
         var item = new Item {
             Key = GenerateStoredKey(key, typeof(T)), Value = JsonConvert.SerializeObject(value)
         };
         context.Items.Add(item);
         await context.SaveChangesAsync();
     }
 }
 public async Task DeleteAsync <T>(string key)
 {
     if (string.IsNullOrEmpty(key))
     {
         throw new ArgumentException("Key MUST have a value");
     }
     using (var context = new GoogleAuthContext())
     {
         var generatedKey = GenerateStoredKey(key, typeof(T));
         var item         = context.Items.FirstOrDefault(x => x.Key == generatedKey);
         if (item != null)
         {
             context.Items.Remove(item);
             await context.SaveChangesAsync();
         }
     }
 }