using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.AspNetCore.Mvc; using MySystem.Models; namespace MySystem { public class UserDictionary { WebCMSEntities db = new WebCMSEntities(); #region UserGroup字典 public Dictionary getUserGroupDic() { List UserGroupList = db.UserGroup.ToList(); Dictionary UserGroupDic = new Dictionary(); foreach (UserGroup subUserGroup in UserGroupList) { UserGroupDic.Add(subUserGroup.Id.ToString(), subUserGroup.Name.ToString()); } return UserGroupDic; } #endregion #region 创客等级字典 public Dictionary getUserLevelSet() { List UserLevelSetList = db.UserLevelSet.ToList(); Dictionary UserLevelSetDic = new Dictionary(); foreach (UserLevelSet subUserLevelSet in UserLevelSetList) { UserLevelSetDic.Add(subUserLevelSet.Id.ToString(), subUserLevelSet.Name.ToString()); } return UserLevelSetDic; } #endregion #region 根据字典key获取字典值 public string getDictionaryNameByKey(Dictionary data, string key) { if (data.ContainsKey(key)) { return data[key]; } return ""; } public string getDictionaryNameById(Dictionary data, int key) { if (data.ContainsKey(key)) { return data[key]; } return ""; } public string getDictionaryNamesByKeys(Dictionary data, string keys) { string result = ""; string[] keylist = keys.Split(','); foreach (string subkey in keylist) { if (data.ContainsKey(subkey)) { result += data[subkey] + ","; } } return result.TrimEnd(','); } #endregion } }