using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNetCore.Mvc;
using MySystem.Models;

namespace MySystem
{
    public class OrderDictionary
    {
        WebCMSEntities db = new WebCMSEntities();


        #region ErpCompanys字典

        public Dictionary<string, string> getErpCompanysDic()
        {
            List<ErpCompanys> ErpCompanysList = db.ErpCompanys.ToList();
            Dictionary<string, string> ErpCompanysDic = new Dictionary<string, string>();
            foreach (ErpCompanys subErpCompanys in ErpCompanysList)
            {
                ErpCompanysDic.Add(subErpCompanys.Id.ToString(), subErpCompanys.Name.ToString());
            }
            return ErpCompanysDic;
        }

        #endregion

        #region OrderRefundReason字典

        public Dictionary<string, string> getOrderRefundReasonDic()
        {
            List<OrderRefundReason> OrderRefundReasonList = db.OrderRefundReason.ToList();
            Dictionary<string, string> OrderRefundReasonDic = new Dictionary<string, string>();
            foreach (OrderRefundReason subOrderRefundReason in OrderRefundReasonList)
            {
                OrderRefundReasonDic.Add(subOrderRefundReason.Id.ToString(), subOrderRefundReason.Name.ToString());
            }
            return OrderRefundReasonDic;
        }

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