Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="propertyId"></param>
        /// <param name="value"></param>
        public void CreatePropertyValues(int propertyId, List <string> value)
        {
            KuanMaiEntities db = new KuanMaiEntities();

            try
            {
                Product_Spec ps = (from prop in db.Product_Spec where prop.Product_Spec_ID == propertyId select prop).FirstOrDefault <Product_Spec>();
                if (ps == null)
                {
                    throw new KMJXCException("属性不存在,不能添加属性值");
                }

                List <Product_Spec_Value> psValues = (from psv in db.Product_Spec_Value where psv.Product_Spec_ID == propertyId select psv).ToList <Product_Spec_Value>();

                if (value != null && value.Count > 0)
                {
                    foreach (string v in value)
                    {
                        Product_Spec_Value propValue = (from propv in psValues where propv.Name == v select propv).FirstOrDefault <Product_Spec_Value>();
                        if (propValue == null)
                        {
                            propValue = new Product_Spec_Value();
                            propValue.Product_Spec_ID = propertyId;
                            propValue.Name            = v;
                            propValue.Mall_PVID       = "";
                            propValue.Created         = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                            db.Product_Spec_Value.Add(propValue);
                        }
                    }

                    db.SaveChanges();
                }
            }
            catch
            {
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="category"></param>
        /// <returns></returns>
        public List <BProperty> GetProperities(Product_Class category, Shop shop)
        {
            List <BProperty>    properities = new List <BProperty>();
            ItempropsGetRequest req         = new ItempropsGetRequest();

            req.Fields = "pid,name,must,multi,prop_values";
            if (category != null && !string.IsNullOrEmpty(category.Mall_CID))
            {
                req.Cid = long.Parse(category.Mall_CID);
            }
            else
            {
                req.Cid = 0;
            }
            //req.IsKeyProp = true;
            req.IsSaleProp  = true;
            req.IsColorProp = true;
            req.IsEnumProp  = true;
            req.IsInputProp = true;
            req.IsItemProp  = true;
            //1=>Taobao
            //2=>TMall, need to check Mall Type from Shop object
            req.Type = 1L;

            ItempropsGetResponse response = client.Execute(req);

            if (response.IsError)
            {
                throw new KMJXCException(response.ErrMsg);
            }

            if (response.ItemProps != null)
            {
                foreach (TB.ItemProp prop in response.ItemProps)
                {
                    BProperty pro = new BProperty();
                    pro.Created    = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    pro.MID        = prop.Pid.ToString();
                    pro.Name       = prop.Name;
                    pro.CategoryId = category.Product_Class_ID;
                    pro.ID         = 0;
                    pro.Shop       = new BShop()
                    {
                        ID = category.Shop_ID
                    };
                    pro.Created_By = new BUser()
                    {
                        ID = category.Create_User_ID
                    };
                    properities.Add(pro);
                    if (prop.PropValues != null)
                    {
                        foreach (TB.PropValue pv in prop.PropValues)
                        {
                            Product_Spec_Value psv = new Product_Spec_Value();
                            psv.Name = pv.Name;
                            pro.Values.Add(psv);
                        }
                    }
                }
            }

            return(properities);
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public Product_Spec CreateNewProperty(int categoryId, string propertyName, List <string> value)
        {
            Product_Spec ps = null;

            if (string.IsNullOrEmpty(propertyName))
            {
                throw new KMJXCException("属性名称不能为空");
            }


            KuanMaiEntities     db         = new KuanMaiEntities();
            List <Product_Spec> properties = new List <Product_Spec>();

            try
            {
                var propes = from props in db.Product_Spec where props.Name == propertyName && props.Shop_ID == this.Shop.Shop_ID select props;
                if (categoryId > 0)
                {
                    propes.Where(c => c.Product_Class_ID == categoryId);
                }

                properties = propes.ToList <Product_Spec>();
                if (properties.Count > 0)
                {
                    throw new KMJXCException("名为" + propertyName + "已经存在");
                }

                ps = new Product_Spec();
                ps.Product_Class_ID = categoryId;
                ps.Shop_ID          = this.Shop.Shop_ID;
                ps.User_ID          = this.CurrentUser.ID;
                ps.Name             = propertyName;
                ps.Created          = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                ps.Mall_PID         = "";

                db.Product_Spec.Add(ps);
                db.SaveChanges();

                int psId = ps.Product_Spec_ID;
                if (psId == 0)
                {
                    throw new KMJXCException("产品属性创建失败");
                }

                if (value != null)
                {
                    foreach (string v in value)
                    {
                        Product_Spec_Value psv = new Product_Spec_Value();
                        psv.Product_Spec_ID = psId;
                        psv.Name            = v;
                        psv.Created         = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                        psv.User_ID         = ps.User_ID;
                        psv.Mall_PVID       = "";
                    }
                }
            }
            catch
            {
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
            return(ps);
        }