コード例 #1
0
ファイル: SettingService.cs プロジェクト: houzhenhuang/ZSZ
 public string GetValue(string name)
 {
     using (ZSZDbContext context = new ZSZDbContext())
     {
         BaseService <SettingEntity> service = new BaseService <SettingEntity>(context);
         SettingEntity entity = service.GetAll().AsNoTracking().SingleOrDefault(p => p.Name == name);
         return(entity == null ? null : entity.Value);
     }
 }
コード例 #2
0
ファイル: SettingService.cs プロジェクト: houzhenhuang/ZSZ
        public void SetValue(string name, string value)
        {
            using (ZSZDbContext context = new ZSZDbContext())
            {
                BaseService <SettingEntity> service = new BaseService <SettingEntity>(context);

                SettingEntity entity = service.GetAll().SingleOrDefault(p => p.Name == name);
                if (entity == null)
                {
                    context.Settings.Add(new SettingEntity {
                        Name = name, Value = value
                    });
                }
                else
                {
                    entity.Value = value;
                }
                context.SaveChanges();
            }
        }