Ejemplo n.º 1
0
 /// <summary>
 /// Returns the first ConfigurationItem that matches the supplied ModuleName and Key.
 /// If one does not exist, then a new one is returned that will need to be saved back to the database to get created.
 /// </summary>
 /// <param name="ModuleName"></param>
 /// <param name="Key"></param>
 /// <returns></returns>
 public static Models.ConfigurationItem GetUniqueItem(string ModuleName, string Key)
 {
     try
     {
         using (var db = new Context.SqlContext())
         {
             db.Configuration.LazyLoadingEnabled = false;
             Models.ConfigurationItem ci = db.ConfigurationItem.Where(i => i.Module == ModuleName && i.Key == Key).FirstOrDefault();
             if (ci != null)
             {
                 return(ci);
             }
             else
             {
                 ci        = new Models.ConfigurationItem();
                 ci.Module = ModuleName;
                 ci.Key    = Key;
                 return(ci);
             }
         }
     }
     catch (Exception ex)
     {
         var msg = ex.Message;
         return(null);
     }
 }
Ejemplo n.º 2
0
 public static int Save(Models.ConfigurationItem configurationItem)
 {
     using (var db = new Context.SqlContext())
     {
         db.Entry(configurationItem).State = configurationItem.ConfigurationItemId.Equals(0) ? EntityState.Added : EntityState.Modified;
         return(db.SaveChanges());
     }
 }
Ejemplo n.º 3
0
 public static string GetValue(string ModuleName, string Key)
 {
     try
     {
         using (var db = new Context.SqlContext())
         {
             db.Configuration.LazyLoadingEnabled = false;
             Models.ConfigurationItem ci = db.ConfigurationItem.Where(i => i.Module == ModuleName && i.Key == Key).FirstOrDefault();
             if ((ci != null) && (ci.Value != null))
             {
                 return(ci.Value);
             }
         }
     }
     catch (Exception ex)
     {
         var msg = ex.Message;
         return("");
     }
     return("");
 }