BootstrapAdmin/Bootstrap.DataAccess/Helper/DictHelper.cs

120 lines
4.1 KiB
C#
Raw Normal View History

2018-10-19 23:09:52 +08:00
using Bootstrap.Security;
using Longbow.Cache;
2018-10-19 23:09:52 +08:00
using Longbow.Data;
using System.Collections.Generic;
namespace Bootstrap.DataAccess
{
/// <summary>
///
/// </summary>
public static class DictHelper
{
/// <summary>
///
/// </summary>
/// <summary>
/// 缓存索引BootstrapAdmin后台清理缓存时使用
/// </summary>
public const string RetrieveDictsDataKey = "BootstrapDict-RetrieveDicts";
/// <summary>
///
/// </summary>
public const string RetrieveCategoryDataKey = "DictHelper-RetrieveDictsCategory";
2018-10-19 23:09:52 +08:00
/// <summary>
///
/// </summary>
/// <returns></returns>
public static IEnumerable<BootstrapDict> RetrieveDicts() => CacheManager.GetOrAdd(RetrieveDictsDataKey, key => DbContextManager.Create<Dict>().RetrieveDicts());
2018-10-19 23:09:52 +08:00
/// <summary>
/// 删除字典中的数据
/// </summary>
/// <param name="value">需要删除的IDs</param>
/// <returns></returns>
public static bool Delete(IEnumerable<string> value)
{
var ret = DbContextManager.Create<Dict>().Delete(value);
CacheCleanUtility.ClearCache(dictIds: value);
return ret;
}
2018-10-19 23:09:52 +08:00
/// <summary>
/// 保存新建/更新的字典信息
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public static bool Save(BootstrapDict p)
{
var ret = DbContextManager.Create<Dict>().Save(p);
if (ret) CacheCleanUtility.ClearCache(dictIds: new List<string>());
return ret;
}
2018-10-19 23:09:52 +08:00
/// <summary>
/// 保存网站个性化设置
/// </summary>
/// <param name="name"></param>
/// <param name="code"></param>
/// <param name="category"></param>
/// <returns></returns>
public static bool SaveSettings(BootstrapDict dict)
{
var ret = DbContextManager.Create<Dict>().SaveSettings(dict);
if (ret) CacheCleanUtility.ClearCache(dictIds: new List<string>());
return ret;
}
2018-10-19 23:09:52 +08:00
/// <summary>
/// 获取字典分类名称
/// </summary>
/// <returns></returns>
public static IEnumerable<string> RetrieveCategories() => CacheManager.GetOrAdd(RetrieveCategoryDataKey, key => DbContextManager.Create<Dict>().RetrieveCategories());
2018-10-19 23:09:52 +08:00
/// <summary>
///
/// </summary>
/// <returns></returns>
public static string RetrieveWebTitle() => DbContextManager.Create<Dict>().RetrieveWebTitle();
2018-10-19 23:09:52 +08:00
/// <summary>
///
/// </summary>
/// <returns></returns>
public static string RetrieveWebFooter() => DbContextManager.Create<Dict>().RetrieveWebFooter();
2018-10-19 23:09:52 +08:00
/// <summary>
/// 获得系统中配置的可以使用的网站样式
/// </summary>
/// <returns></returns>
public static IEnumerable<BootstrapDict> RetrieveThemes() => DbContextManager.Create<Dict>().RetrieveThemes();
2018-10-19 23:09:52 +08:00
/// <summary>
/// 获得网站设置中的当前样式
/// </summary>
/// <returns></returns>
public static string RetrieveActiveTheme() => DbContextManager.Create<Dict>().RetrieveActiveTheme();
2018-10-19 23:09:52 +08:00
/// <summary>
/// 获取头像路径
/// </summary>
/// <returns></returns>
public static string RetrieveIconFolderPath() => DbContextManager.Create<Dict>().RetrieveIconFolderPath();
2018-10-19 23:09:52 +08:00
/// <summary>
/// 获得默认的前台首页地址,默认为~/Home/Index
/// </summary>
/// <param name="appCode">应用程序编码</param>
2018-10-19 23:09:52 +08:00
/// <returns></returns>
public static string RetrieveHomeUrl(string appCode) => DbContextManager.Create<Dict>().RetrieveHomeUrl(appCode);
2018-10-19 23:09:52 +08:00
/// <summary>
///
/// </summary>
/// <returns></returns>
public static IEnumerable<KeyValuePair<string, string>> RetrieveApps() => DbContextManager.Create<Dict>().RetrieveApps();
2018-10-19 23:09:52 +08:00
}
}