UserDictionary.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using Microsoft.AspNetCore.Mvc;
  6. using MySystem.Models;
  7. namespace MySystem
  8. {
  9. public class UserDictionary
  10. {
  11. WebCMSEntities db = new WebCMSEntities();
  12. #region UserGroup字典
  13. public Dictionary<string, string> getUserGroupDic()
  14. {
  15. List<UserGroup> UserGroupList = db.UserGroup.ToList();
  16. Dictionary<string, string> UserGroupDic = new Dictionary<string, string>();
  17. foreach (UserGroup subUserGroup in UserGroupList)
  18. {
  19. UserGroupDic.Add(subUserGroup.Id.ToString(), subUserGroup.Name.ToString());
  20. }
  21. return UserGroupDic;
  22. }
  23. #endregion
  24. #region 创客等级字典
  25. public Dictionary<string, string> getUserLevelSet()
  26. {
  27. List<UserLevelSet> UserLevelSetList = db.UserLevelSet.ToList();
  28. Dictionary<string, string> UserLevelSetDic = new Dictionary<string, string>();
  29. foreach (UserLevelSet subUserLevelSet in UserLevelSetList)
  30. {
  31. UserLevelSetDic.Add(subUserLevelSet.Id.ToString(), subUserLevelSet.Name.ToString());
  32. }
  33. return UserLevelSetDic;
  34. }
  35. #endregion
  36. #region 根据字典key获取字典值
  37. public string getDictionaryNameByKey(Dictionary<string, string> data, string key)
  38. {
  39. if (data.ContainsKey(key))
  40. {
  41. return data[key];
  42. }
  43. return "";
  44. }
  45. public string getDictionaryNameById(Dictionary<int, string> data, int key)
  46. {
  47. if (data.ContainsKey(key))
  48. {
  49. return data[key];
  50. }
  51. return "";
  52. }
  53. public string getDictionaryNamesByKeys(Dictionary<string, string> data, string keys)
  54. {
  55. string result = "";
  56. string[] keylist = keys.Split(',');
  57. foreach (string subkey in keylist)
  58. {
  59. if (data.ContainsKey(subkey))
  60. {
  61. result += data[subkey] + ",";
  62. }
  63. }
  64. return result.TrimEnd(',');
  65. }
  66. #endregion
  67. }
  68. }