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<string, string> getUserGroupDic()
        {
            List<UserGroup> UserGroupList = db.UserGroup.ToList();
            Dictionary<string, string> UserGroupDic = new Dictionary<string, string>();
            foreach (UserGroup subUserGroup in UserGroupList)
            {
                UserGroupDic.Add(subUserGroup.Id.ToString(), subUserGroup.Name.ToString());
            }
            return UserGroupDic;
        }

        #endregion

        #region 创客等级字典

        public Dictionary<string, string> getUserLevelSet()
        {
            List<UserLevelSet> UserLevelSetList = db.UserLevelSet.ToList();
            Dictionary<string, string> UserLevelSetDic = new Dictionary<string, string>();
            foreach (UserLevelSet subUserLevelSet in UserLevelSetList)
            {
                UserLevelSetDic.Add(subUserLevelSet.Id.ToString(), subUserLevelSet.Name.ToString());
            }
            return UserLevelSetDic;
        }

        #endregion







        #region 根据字典key获取字典值

        public string getDictionaryNameByKey(Dictionary<string, string> data, string key)
        {
            if (data.ContainsKey(key))
            {
                return data[key];
            }
            return "";
        }
        public string getDictionaryNameById(Dictionary<int, string> data, int key)
        {
            if (data.ContainsKey(key))
            {
                return data[key];
            }
            return "";
        }
        public string getDictionaryNamesByKeys(Dictionary<string, string> 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
    }
}