예제 #1
0
        public long AddConfig(AtomConfiger cfg, string parentKey)
        {
            using (var db = new Db())
            {
                if (!string.IsNullOrEmpty(parentKey))
                {
                    var conf = GetConfig(parentKey);
                    if (conf == null)
                    {
                        throw new Exception("没有上级配置");
                    }
                    cfg.ParentId = conf.Id;
                }

                var exist = db.Top <AtomConfiger>(t => t.Key == cfg.Key);
                if (exist == null)
                {
                    return(db.Insert(cfg));
                }

                exist.Name        = cfg.Name;
                exist.ParentId    = cfg.ParentId;
                exist.Value       = cfg.Value;
                exist.Version     = cfg.Version;
                exist.Description = cfg.Description;
                exist.EditTime    = DateTime.Now;
                return(db.Update(exist));
            }
        }
예제 #2
0
        public static bool Set(string key, string value, string parentKey = "", string name = "", string desc = "", int version = 1)
        {
            var cc = new AtomConfiger()
            {
                Key         = key,
                Value       = value,
                Version     = version,
                Name        = name,
                Description = desc,
                AddTime     = DateTime.Now,
                EditTime    = DateTime.Now,
                Enable      = true
            };

            return(Confm.AddConfig(cc, parentKey) > 0);
        }