using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.AspNetCore.Mvc; using MySystem.Models; namespace MySystem { public class MerchantDictionary { WebCMSEntities db = new WebCMSEntities(); #region 商家字典 public Dictionary getMerchantsDic() { List MerchantsList = db.Merchants.ToList(); Dictionary MerchantsDic = new Dictionary(); foreach (Merchants subMerchants in MerchantsList) { MerchantsDic.Add(subMerchants.Id.ToString(), subMerchants.Name.ToString()); } return MerchantsDic; } #endregion #region MerchantClass字典 public Dictionary getMerchantClassDic(int MerchantId) { List MerchantClassList = db.MerchantClass.Where(m => m.MerchantId == MerchantId).ToList(); Dictionary MerchantClassDic = new Dictionary(); foreach (MerchantClass subMerchantClass in MerchantClassList) { MerchantClassDic.Add(subMerchantClass.Id.ToString(), subMerchantClass.ColName.ToString()); } return MerchantClassDic; } #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 } }