예제 #1
0
        public ActionResult <object> GetBack(int Product_ID)
        {
            var(pList, prList, paList, rpList) = this._repository.GetBack(Product_ID);
            b_productVM productVM = null;

            foreach (var p in pList)
            {
                productVM = p.ConvertToT <b_productVM>();
                productVM.product_resourcesList = prList.Select(pr => pr.ConvertToT <b_product_resourcesVM>()).ToList();
                productVM.product_attributeList = paList.Select(pa => pa.ConvertToT <b_product_attributeVM>()).ToList();
                //productVM.rel_productList = rpList.Select(rp => rp.ConvertToT<b_productVM>()).ToList();
                productVM.rel_productList = new List <b_productVM>();

                if (rpList != null && rpList.Count() > 0)
                {
                    var(r_pList, r_prList) = this._repository.GetProductListByIDs <b_product_Entity, b_product_resources_Entity>(rpList.Select(rp => rp.Product_ID));
                    foreach (var rp in r_pList)
                    {
                        b_productVM r_productVM = rp.ConvertToT <b_productVM>();
                        r_productVM.product_resourcesList = r_prList.Where(pr => pr.Product_ID == rp.Product_ID).Select(pr => pr.ConvertToT <b_product_resourcesVM>()).ToList();
                        productVM.rel_productList.Add(r_productVM);
                    }
                }

                break;
            }
            return(productVM.ResponseSuccess());
        }
예제 #2
0
        public ActionResult <object> Get(Lang lang, int Product_ID)
        {
            string      key       = string.Format(Constant.Cache_Product, Product_ID, lang);
            b_productVM productVM = CacheFactory.CacheInstance.Get <b_productVM>(key);

            if (productVM == null)
            {
                var(pList, prList, paList, rpList) = this._repository.Get(Product_ID);
                foreach (var p in pList)
                {
                    productVM = p.ConvertToT <b_productVM>();
                    productVM.product_resourcesList = prList.Select(pr => pr.ConvertToT <b_product_resourcesVM>()).ToList();
                    productVM.product_attributeList = paList.Select(pa => pa.ConvertToT <b_product_attributeVM>()).ToList();
                    productVM.rel_productList       = new List <b_productVM>();
                    if (rpList != null && rpList.Count() > 0)
                    {
                        var(r_pList, r_prList) = this._repository.GetProductListByIDs <b_product_Entity, b_product_resources_Entity>(rpList.Select(rp => rp.Product_ID));
                        foreach (var rp in r_pList)
                        {
                            b_productVM r_productVM = rp.ConvertToT <b_productVM>();
                            switch (lang)
                            {
                            case Lang.CHS:
                                r_productVM.Product_Name_HK = r_productVM.Product_Name_CH;
                                break;

                            case Lang.CHT:
                                r_productVM.Product_Name_CH = r_productVM.Product_Name_HK;
                                break;
                            }
                            r_productVM.product_resourcesList = r_prList.Where(pr => pr.Product_ID == rp.Product_ID).Select(pr => pr.ConvertToT <b_product_resourcesVM>()).ToList();
                            productVM.rel_productList.Add(r_productVM);
                        }
                    }
                    switch (lang)
                    {
                    case Lang.CHS:
                        productVM.Product_Name_HK = productVM.Product_Name_CH;
                        if (productVM.product_attributeList != null)
                        {
                            foreach (var a in productVM.product_attributeList)
                            {
                                a.P_Attribute_Name_HK  = a.P_Attribute_Name_CH;
                                a.P_Attribute_Value_HK = a.P_Attribute_Value_CH;
                            }
                        }
                        if (productVM.rel_productList != null)
                        {
                            foreach (var pr in productVM.rel_productList)
                            {
                                p.Product_Name_HK = p.Product_Name_CH;
                            }
                        }
                        break;

                    case Lang.CHT:
                        productVM.Product_Name_CH = productVM.Product_Name_HK;
                        if (productVM.product_attributeList != null)
                        {
                            foreach (var a in productVM.product_attributeList)
                            {
                                a.P_Attribute_Name_CH  = a.P_Attribute_Name_HK;
                                a.P_Attribute_Value_CH = a.P_Attribute_Value_HK;
                            }
                        }
                        if (productVM.rel_productList != null)
                        {
                            foreach (var pr in productVM.rel_productList)
                            {
                                p.Product_Name_CH = p.Product_Name_HK;
                            }
                        }
                        break;
                    }
                    break;
                }
                CacheFactory.CacheInstance.Add(key, productVM);
            }
            return(productVM.ResponseSuccess());
        }