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

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


        #region 优惠券字典

        public Dictionary<string, string> getCouponsDic()
        {
            List<Coupons> CouponsList = db.Coupons.Where(m => m.Status == 1).ToList();
            Dictionary<string, string> CouponsDic = new Dictionary<string, string>();
            foreach (Coupons subCoupons in CouponsList)
            {
                CouponsDic.Add(subCoupons.Id.ToString(), subCoupons.Name.ToString());
            }
            return CouponsDic;
        }

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