using System;
using System.Collections.Generic;
using CB.Cache;
using CB.Entity;
using CB.Interface.Infrastructure;
namespace CB.Data
{
///
/// 系统用户组操作类 by JNswins
///
public class SysGroupService
{
///
/// 移除缓存
///
protected static void RemoveCache()
{
CB.Cache.CBCache.GetCacheService().RemoveObject(CB.Cache.CacheKeys.SysGroupList);
}
///
/// 新增保存
///
///
///
public static bool Save(SysGroupInfo entity)
{
bool yes = DatabaseProvider.GetDbProvider().Save(entity);
if (yes)
{
RemoveCache(); return true;
}
return false;
}
///
/// 更新信息
///
///
///
public static bool Update(SysGroupInfo entity)
{
bool yes = DatabaseProvider.GetDbProvider().Update(entity);
if (yes)
{
RemoveCache(); return true;
}
return false;
}
///
/// 删除
///
///
///
public static bool Delete(int id)
{
bool yes = DatabaseProvider.GetDbProvider().Delete(id);
if (yes)
{
RemoveCache(); return true;
}
return false;
}
///
/// 获取详细
///
/// 用户组ID
///
public static SysGroupInfo Get(int id)
{
var list = ToList();
if (null == list || 0 >= list.Count)
return null;
SysGroupInfo entity = null;
for (int i = list.Count - 1; i >= 0; i--)
{
if (id == list[i].GroupId)
entity = list[i];
}
return entity;
}
///
/// 所有数据列表
///
///
public static IList ToList()
{
var list = CB.Cache.CBCache.GetCacheService().GetObject(CB.Cache.CacheKeys.SysGroupList) as IList;
if (null == list || 0 >= list.Count)
{
list = DatabaseProvider.GetDbProvider().ToList();
CB.Cache.CBCache.GetCacheService().AddObject(CB.Cache.CacheKeys.SysGroupList, list);
}
return list;
}
}
}