Ejemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="categoryId"></param>
        /// <param name="propName"></param>
        /// <param name="propValues"></param>
        /// <returns></returns>
        public BProperty CreateProperty(int categoryId,string propName,List<string> propValues,int shop_id=0)
        {
            BProperty bproperty = null;
            if (string.IsNullOrEmpty(propName))
            {
                throw new KMJXCException("属性名称不能为空");
            }
            KuanMaiEntities db = new KuanMaiEntities();
            try
            {
                var existed = from props in db.Product_Spec where props.Name==propName select props;

                if (categoryId > 0)
                {
                    //existed = existed.Where(a=>a.Product_Class_ID==categoryId);
                }

                if (this.Shop.Parent_Shop_ID > 0)
                {
                    var pexisted = existed.Where(a=>a.Shop_ID==this.Main_Shop.Shop_ID);
                    if (pexisted.FirstOrDefault<Product_Spec>() != null)
                    {
                        throw new KMJXCException("主店铺已经有此属性,不能重复创建,请使用现有主店铺的属性");
                    }
                }

                existed = existed.Where(a => a.Shop_ID == this.Shop.Shop_ID);
                if (existed.FirstOrDefault<Product_Spec>() != null)
                {
                    throw new KMJXCException("此属性已经存在,不能重复创建");
                }

                Product_Spec property = new Product_Spec();
                property.Product_Class_ID = categoryId;
                property.Name = propName;
                property.User_ID = this.CurrentUser.ID;
                property.Shop_ID = this.Shop.Shop_ID;
                if (shop_id > 0)
                {
                    property.Shop_ID = shop_id;
                }
                property.Mall_PID = "";
                property.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                db.Product_Spec.Add(property);
                db.SaveChanges();
                if (property.Product_Spec_ID <= 0)
                {
                    throw new KMJXCException("属性创建失败");
                }
                bproperty = new BProperty();
                bproperty.ID = property.Product_Spec_ID;
                bproperty.Created_By = this.CurrentUser;
                bproperty.Created = (int)property.Created;
                bproperty.CategoryId = categoryId;
                bproperty.MID = "";
                bproperty.Name = propName;

                if (propValues != null)
                {
                    if (bproperty.Values == null)
                    {
                        bproperty.Values = new List<Product_Spec_Value>();
                    }
                    foreach (string v in propValues)
                    {
                        Product_Spec_Value psv = new Product_Spec_Value();
                        psv.Mall_PVID = "";
                        psv.Name = v;
                        psv.Product_Spec_ID = property.Product_Spec_ID;
                        psv.Product_Spec_Value_ID = 0;
                        psv.User_ID = this.CurrentUser.ID;
                        psv.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                        db.Product_Spec_Value.Add(psv);
                    }
                    db.SaveChanges();
                    bproperty.Values=(from pv in db.Product_Spec_Value where pv.Product_Spec_ID==property.Product_Spec_ID select pv).ToList<Product_Spec_Value>();
                }
            }
            catch(KMJXCException ex)
            {
                throw ex;
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
            return bproperty;
        }
Ejemplo n.º 2
0
        public ApiMessage CreateProperty()
        {
            BProperty property = new BProperty();
            ApiMessage message = new ApiMessage();
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            Shop currentShop = userMgr.Shop;
            ShopCategoryManager cateMgr = new ShopCategoryManager(userMgr.CurrentUser, currentShop, userMgr.CurrentUserPermission);
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string categoryId = request["category_id"];
            string propName = request["prop_name"];
            string propValue = request["prop_value"];
            List<string> propValues = new List<string>();
            if (!string.IsNullOrEmpty(propValue))
            {
                string[] vs = propValue.Split(',');
                if (vs != null && vs.Length > 0)
                {
                    for (int i = 0; i < vs.Length; i++)
                    {
                        propValues.Add(vs[i]);
                    }
                }
            }

            try
            {
                property = cateMgr.CreateProperty(int.Parse(categoryId), propName, propValues);
                message.Item = property;
                message.Status = "ok";
            }
            catch (KM.JXC.Common.KMException.KMJXCException ex)
            {
                message.Status = "failed";
                message.Message = ex.Message;
                message.Item = null;
            }
            catch (Exception nex)
            {

            }

            return message;
        }
Ejemplo n.º 3
0
        public BProperty GetProperty()
        {
            BProperty property = new BProperty();
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            Shop MainShop = userMgr.Main_Shop;
            ShopCategoryManager cateMgr = new ShopCategoryManager(userMgr.CurrentUser, MainShop, userMgr.CurrentUserPermission);
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            int propId = 0;
            int.TryParse(request["prop_id"],out propId);
            List<BProperty> properties = cateMgr.GetProperties(0,propId);
            if (properties.Count == 1)
            {
                property = properties[0];
            }

            return property;
        }
Ejemplo n.º 4
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;
        }