using System;
using System.Collections.Generic;
using System.Linq;
using MySystem.PxcModels;

namespace MySystem
{
    public class RelationClass
    {

        public static string GetUserLevelSetInfo(int key)
        {
            using (WebCMSEntities db = new WebCMSEntities())
            {
                UserLevelSet item = db.UserLevelSet.FirstOrDefault(m => m.Id == key);
                if (item != null)
                {
                    return item.Name;
                }
            }
            return "";
        }

        public static string GetUserGroupList(string keys)
        {
            string[] IdList = keys.Split(',');
            List<int> List = new List<int>();
            foreach (string key in IdList)
            {
                List.Add(int.Parse(key));
            }
            string result = "";
            using (WebCMSEntities db = new WebCMSEntities())
            {
                var items = db.UserGroup.Select(m => new { m.Id, m.Name }).Where(m => List.Contains(m.Id));
                foreach (var item in items)
                {
                    result += item.Name + ",";
                }
            }
            return result.TrimEnd(',');
        }

        public static string GetColInfo(int key)
        {
            using (WebCMSEntities db = new WebCMSEntities())
            {
                Col item = db.Col.FirstOrDefault(m => m.Id == key);
                if (item != null)
                {
                    return item.ColName;
                }
            }
            return "";
        }

        public static string GetColList(string keys)
        {
            string[] IdList = keys.Split(',');
            List<int> List = new List<int>();
            foreach (string key in IdList)
            {
                List.Add(int.Parse(key));
            }
            string result = "";
            using (WebCMSEntities db = new WebCMSEntities())
            {
                var items = db.Col.Select(m => new { m.Id, m.ColName }).Where(m => List.Contains(m.Id));
                foreach (var item in items)
                {
                    result += item.ColName + ",";
                }
            }
            return result.TrimEnd(',');
        }

        public static string GetProductFareTempInfo(int key)
        {
            using (WebCMSEntities db = new WebCMSEntities())
            {
                ProductFareTemp item = db.ProductFareTemp.FirstOrDefault(m => m.Id == key);
                if (item != null)
                {
                    return item.Name;
                }
            }
            return "";
        }

        public static string GetMerchantClassInfo(int key)
        {
            using (WebCMSEntities db = new WebCMSEntities())
            {
                MerchantClass item = db.MerchantClass.FirstOrDefault(m => m.Id == key);
                if (item != null)
                {
                    return item.ColName;
                }
            }
            return "";
        }

        public static string GetMerchantColInfo(string key)
        {
            using (WebCMSEntities db = new WebCMSEntities())
            {
                MerchantCol item = db.MerchantCol.FirstOrDefault(m => m.ColId == key);
                if (item != null)
                {
                    return item.ColName;
                }
            }
            return "";
        }

        public static string GetUsersInfo(int key)
        {
            using (WebCMSEntities db = new WebCMSEntities())
            {
                Users item = db.Users.FirstOrDefault(m => m.Id == key);
                if (item != null)
                {
                    return item.MakerCode;
                }
            }
            return "";
        }

        public static string GetErpCompanysInfo(string key)
        {
            using (WebCMSEntities db = new WebCMSEntities())
            {
                ErpCompanys item = db.ErpCompanys.FirstOrDefault(m => m.Name == key);
                if (item != null)
                {
                    return item.Name;
                }
            }
            return "";
        }

        public static string GetMerchantsInfo(int key)
        {
            using (WebCMSEntities db = new WebCMSEntities())
            {
                Merchants item = db.Merchants.FirstOrDefault(m => m.Id == key);
                if (item != null)
                {
                    return item.Name;
                }
            }
            return "";
        }

        public static string GetOrderRefundReasonInfo(int key)
        {
            using (WebCMSEntities db = new WebCMSEntities())
            {
                OrderRefundReason item = db.OrderRefundReason.FirstOrDefault(m => m.Id == key);
                if (item != null)
                {
                    return item.Name;
                }
            }
            return "";
        }

        public static string GetMerchantsList(string keys)
        {
            string[] IdList = keys.Split(',');
            List<int> List = new List<int>();
            foreach (string key in IdList)
            {
                List.Add(int.Parse(key));
            }
            string result = "";
            using (WebCMSEntities db = new WebCMSEntities())
            {
                var items = db.Merchants.Select(m => new { m.Id, m.Name }).Where(m => List.Contains(m.Id));
                foreach (var item in items)
                {
                    result += item.Name + ",";
                }
            }
            return result.TrimEnd(',');
        }

        public static string GetProductsList(string keys)
        {
            string[] IdList = keys.Split(',');
            List<int> List = new List<int>();
            foreach (string key in IdList)
            {
                List.Add(int.Parse(key));
            }
            string result = "";
            using (WebCMSEntities db = new WebCMSEntities())
            {
                var items = db.Products.Select(m => new { m.Id, m.ProductName }).Where(m => List.Contains(m.Id));
                foreach (var item in items)
                {
                    result += item.ProductName + ",";
                }
            }
            return result.TrimEnd(',');
        }

        public static string GetCouponsList(string keys)
        {
            string[] IdList = keys.Split(',');
            List<int> List = new List<int>();
            foreach (string key in IdList)
            {
                List.Add(int.Parse(key));
            }
            string result = "";
            using (WebCMSEntities db = new WebCMSEntities())
            {
                var items = db.Coupons.Select(m => new { m.Id, m.Name }).Where(m => List.Contains(m.Id));
                foreach (var item in items)
                {
                    result += item.Name + ",";
                }
            }
            return result.TrimEnd(',');
        }

        public static string GetKqProductsInfo(int key)
        {
            using (WebCMSEntities db = new WebCMSEntities())
            {
                KqProducts item = db.KqProducts.FirstOrDefault(m => m.Id == key);
                if (item != null)
                {
                    return item.Name;
                }
            }
            return "";
        }

        public static string GetMerchantInfoInfo(int key)
        {
            using (WebCMSEntities db = new WebCMSEntities())
            {
                MerchantInfo item = db.MerchantInfo.FirstOrDefault(m => m.Id == key);
                if (item != null)
                {
                    return item.Name;
                }
            }
            return "";
        }

        public static string GetKqProductBrandList(string keys)
        {
            string[] IdList = keys.Split(',');
            List<int> List = new List<int>();
            foreach (string key in IdList)
            {
                List.Add(int.Parse(key));
            }
            string result = "";
            using (WebCMSEntities db = new WebCMSEntities())
            {
                var items = db.KqProductBrand.Select(m => new { m.Id, m.Name }).Where(m => List.Contains(m.Id));
                foreach (var item in items)
                {
                    result += item.Name + ",";
                }
            }
            return result.TrimEnd(',');
        }

        public static string GetStoreHouseInfo(int key)
        {
            using (WebCMSEntities db = new WebCMSEntities())
            {
                StoreHouse item = db.StoreHouse.FirstOrDefault(m => m.Id == key);
                if (item != null)
                {
                    return item.StoreName;
                }
            }
            return "";
        }

        public static string GetActivityInfoInfo(int key)
        {
            using (WebCMSEntities db = new WebCMSEntities())
            {
                ActivityInfo item = db.ActivityInfo.FirstOrDefault(m => m.Id == key);
                if (item != null)
                {
                    return item.ActName;
                }
            }
            return "";
        }

        public static string GetKqProductBrandInfo(int key)
        {
            using (WebCMSEntities db = new WebCMSEntities())
            {
                KqProductBrand item = db.KqProductBrand.FirstOrDefault(m => m.Id == key);
                if (item != null)
                {
                    return item.Name;
                }
            }
            return "";
        }

        public static string GetUserBackKindInfo(int key)
        {
            using (WebCMSEntities db = new WebCMSEntities())
            {
                UserBackKind item = db.UserBackKind.FirstOrDefault(m => m.Id == key);
                if (item != null)
                {
                    return item.Name;
                }
            }
            return "";
        }

        public static string GetPageUpdateInfoList(string keys)
        {
            string[] ModulePathList = keys.Split(',');
            List<string> List = new List<string>();
            foreach (string key in ModulePathList)
            {
                List.Add(key);
            }
            string result = "";
            using (WebCMSEntities db = new WebCMSEntities())
            {
                var items = db.PageUpdateInfo.Select(m => new { m.ModulePath, m.Title }).Where(m => List.Contains(m.ModulePath));
                foreach (var item in items)
                {
                    result += item.Title + ",";
                }
            }
            return result.TrimEnd(',');
        }

        public static string GetTeamApplyInfo(int key)
        {
            using (WebCMSEntities db = new WebCMSEntities())
            {
                TeamApply item = db.TeamApply.FirstOrDefault(m => m.Id == key);
                if (item != null)
                {
                    return item.TeamNo;
                }
            }
            return "";
        }

        public static string GetProfitObjectsActivesInfo(int key)
        {
            using (WebCMSEntities db = new WebCMSEntities())
            {
                ProfitObjectsActives item = db.ProfitObjectsActives.FirstOrDefault(m => m.Id == key);
                if (item != null)
                {
                    return item.Name;
                }
            }
            return "";
        }

        public static string GetProfitObjectsActivesList(string keys)
        {
            string[] IdList = keys.Split(',');
            List<int> List = new List<int>();
            foreach (string key in IdList)
            {
                List.Add(int.Parse(key));
            }
            string result = "";
            using (WebCMSEntities db = new WebCMSEntities())
            {
                var items = db.ProfitObjectsActives.Select(m => new { m.Id, m.Name }).Where(m => List.Contains(m.Id));
                foreach (var item in items)
                {
                    result += item.Name + ",";
                }
            }
            return result.TrimEnd(',');
        }

        public static string GetProductsInfo(int key)
        {
            using (WebCMSEntities db = new WebCMSEntities())
            {
                Products item = db.Products.FirstOrDefault(m => m.Id == key);
                if (item != null)
                {
                    return item.ProductName;
                }
            }
            return "";
        }

        public static string GetAppVideoInfo(int key)
        {
            using (WebCMSEntities db = new WebCMSEntities())
            {
                AppVideo item = db.AppVideo.FirstOrDefault(m => m.Id == key);
                if (item != null)
                {
                    return item.Name;
                }
            }
            return "";
        }



    }
}