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

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


        #region ProductFareTemp字典

        public Dictionary<string, string> getProductFareTempDic(int MerchantId)
        {
            List<ProductFareTemp> ProductFareTempList = db.ProductFareTemp.Where(m => m.MerchantId == MerchantId).ToList();
            Dictionary<string, string> ProductFareTempDic = new Dictionary<string, string>();
            foreach (ProductFareTemp subProductFareTemp in ProductFareTempList)
            {
                ProductFareTempDic.Add(subProductFareTemp.Id.ToString(), subProductFareTemp.Name.ToString());
            }
            return ProductFareTempDic;
        }

        #endregion

        #region 规格模板字典

        public Dictionary<string, string> getProductNormTempDic(int MerchantId)
        {
            List<ProductNormTemp> ProductNormTempList = db.ProductNormTemp.Where(m => m.MerchantId == MerchantId).ToList();
            Dictionary<string, string> ProductNormTempDic = new Dictionary<string, string>();
            foreach (ProductNormTemp subProductNormTemp in ProductNormTempList)
            {
                ProductNormTempDic.Add(subProductNormTemp.Id.ToString(), subProductNormTemp.Name.ToString());
            }
            return ProductNormTempDic;
        }

        #endregion


        #region Products字典

        public Dictionary<string, string> getProductsDic()
        {
            List<Products> ProductsList = db.Products.ToList();
            Dictionary<string, string> ProductsDic = new Dictionary<string, string>();
            foreach (Products subProducts in ProductsList)
            {
                ProductsDic.Add(subProducts.Id.ToString(), subProducts.ProductName.ToString());
            }
            return ProductsDic;
        }

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