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<string, string> getMerchantsDic()
        {
            List<Merchants> MerchantsList = db.Merchants.ToList();
            Dictionary<string, string> MerchantsDic = new Dictionary<string, string>();
            foreach (Merchants subMerchants in MerchantsList)
            {
                MerchantsDic.Add(subMerchants.Id.ToString(), subMerchants.Name.ToString());
            }
            return MerchantsDic;
        }

        #endregion

        #region MerchantClass字典

        public Dictionary<string, string> getMerchantClassDic(int MerchantId)
        {
            List<MerchantClass> MerchantClassList = db.MerchantClass.Where(m => m.MerchantId == MerchantId).ToList();
            Dictionary<string, string> MerchantClassDic = new Dictionary<string, string>();
            foreach (MerchantClass subMerchantClass in MerchantClassList)
            {
                MerchantClassDic.Add(subMerchantClass.Id.ToString(), subMerchantClass.ColName.ToString());
            }
            return MerchantClassDic;
        }

        #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
    }
}