예제 #1
0
 public void Set <TView>(object value, params object[] parameters)
 {
     try
     {
         var key    = typeof(TView).GetViewKey(parameters);
         var entity = JsonViews.SingleOrDefault(x => x.Key == key);
         var json   = JsonConvert.SerializeObject(value);
         if (entity == null)
         {
             entity = new JsonView
             {
                 Key          = key,
                 Value        = json,
                 UpdatedOnUtc = DateTime.UtcNow,
             };
             JsonViews.Add(entity);
         }
         entity.Value        = json;
         entity.UpdatedOnUtc = DateTime.UtcNow;
         SaveChanges();
     }
     catch (Exception)
     {
         Set <TView>(value, parameters);
     }
 }
예제 #2
0
 public TView Get <TView>(params object[] parameters)
 {
     try
     {
         var key    = typeof(TView).GetViewKey(parameters);
         var entity = JsonViews.AsNoTracking().SingleOrDefault(x => x.Key == key);
         if (entity == null)
         {
             entity = new JsonView
             {
                 Key          = key,
                 UpdatedOnUtc = DateTime.UtcNow,
             };
             JsonViews.Add(entity);
             SaveChanges();
             return(default(TView));
         }
         if (string.IsNullOrWhiteSpace(entity.Value))
         {
             return(default(TView));
         }
         var value = JsonConvert.DeserializeObject <TView>(entity.Value);
         return(value);
     }
     catch (Exception)
     {
         return(Get <TView>(parameters));
     }
 }