public string CategorySort(string pRequest)
        {
            var rp = pRequest.DeserializeJSONTo <APIRequest <CategorySortRP> >();
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            var rd = new SaveSkuRD();//返回值


            var service = new ItemCategoryService(loggingSessionInfo);//保存到商品分类表

            //  var skuPropServer = new SkuPropServer(loggingSessionInfo);//保存到T_Sku_Property

            if (rp.Parameters.CategoryList == null)
            {
                throw new APIException("缺少参数【CategoryList】或参数值为空")
                      {
                          ErrorCode = 135
                      };
            }


            foreach (var item in rp.Parameters.CategoryList)
            {
                service.SetItemCategoryDisplayIndex(loggingSessionInfo, item.Item_Category_Id, item.DisplayIndex == null ? 0 : (int)item.DisplayIndex);
            }



            var rsp = new SuccessResponse <IAPIResponseData>(rd);

            return(rsp.ToJSON());
        }
        public string SaveSkuValue(string pRequest)
        {
            var rp = pRequest.DeserializeJSONTo <APIRequest <SaveSkuValueRP> >();
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            var rd = new SaveSkuRD();//返回值

            //处理促销分组
            //先把之前的删除掉
            var service = new PropService(loggingSessionInfo);//保存到t_sku表

            //  var skuPropServer = new SkuPropServer(loggingSessionInfo);//保存到T_Sku_Property

            if (string.IsNullOrEmpty(rp.Parameters.parent_prop_id))
            {
                throw new APIException("缺少参数【parent_prop_id】或参数值为空")
                      {
                          ErrorCode = 135
                      };
            }
            if (string.IsNullOrEmpty(rp.Parameters.prop_name))
            {
                throw new APIException("缺少参数【prop_name】或参数值为空")
                      {
                          ErrorCode = 135
                      };
            }

            string   error    = "";
            PropInfo itemInfo = new PropInfo();

            itemInfo.Prop_Id            = Guid.NewGuid().ToString();
            itemInfo.Prop_Name          = rp.Parameters.prop_name;
            itemInfo.Prop_Code          = itemInfo.Prop_Name;
            itemInfo.Prop_Eng_Name      = "";
            itemInfo.Prop_Type          = "3";                          //属性类型 1=组,2=属性,3=属性明细';
            itemInfo.Parent_Prop_id     = rp.Parameters.parent_prop_id; //父类id
            itemInfo.Prop_Level         = 2;
            itemInfo.Prop_Domain        = "SKU";
            itemInfo.Prop_Input_Flag    = "select";
            itemInfo.Prop_Max_Length    = 1000;
            itemInfo.Prop_Default_Value = "";
            itemInfo.Prop_Status        = 1;
            // itemInfo.Display_Index = ++i;
            if (service.CheckProp(itemInfo))//判断在同一个父类下面,是不是有这个属性代码了。
            {
                throw new APIException("该sku下面,已经有这个sku值了")
                      {
                          ErrorCode = 135
                      };
            }


            var children = service.GetPropListByParentId("SKU", rp.Parameters.parent_prop_id);
            int i        = children == null ? 0 : children.Count;

            itemInfo.Display_Index = ++i;
            service.SaveProp(itemInfo, ref error);



            var rsp = new SuccessResponse <IAPIResponseData>(rd);

            return(rsp.ToJSON());
        }
        public string SaveSku(string pRequest)
        {
            var rp = pRequest.DeserializeJSONTo <APIRequest <SaveSkuRP> >();
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            var rd = new SaveSkuRD();//返回值

            //处理促销分组
            //先把之前的删除掉
            var service = new PropService(loggingSessionInfo);         //保存到t_sku表
            //    var brandDetailBLL = new BrandDetailBLL(CurrentUserInfo);
            var skuPropServer = new SkuPropServer(loggingSessionInfo); //保存到T_Sku_Property
            var propInfo      = rp.Parameters.SkuProp;

            //验证重复性
            int DistinctchildrenCount = propInfo.Children.Select(m => m.Prop_Name).Distinct().Count();

            if (DistinctchildrenCount != propInfo.Children.Count)
            {
                throw new APIException("规格的值不能重复添加")
                      {
                          ErrorCode = 135
                      };
            }

            if (string.IsNullOrEmpty(propInfo.Prop_Name))
            {
                throw new APIException("缺少参数【Prop_Name】或参数值为空")
                      {
                          ErrorCode = 135
                      };
            }

            bool isNew = false;

            if (string.IsNullOrEmpty(propInfo.Prop_Id))
            {
                propInfo.Prop_Id = Guid.NewGuid().ToString();
                isNew            = true;
            }
            propInfo.Prop_Code          = propInfo.Prop_Name;
            propInfo.Prop_Eng_Name      = "";
            propInfo.Prop_Type          = "2";//属性类型 1=组,2=属性,3=属性明细';
            propInfo.Parent_Prop_id     = "-99";
            propInfo.Prop_Level         = 1;
            propInfo.Prop_Domain        = "SKU";
            propInfo.Prop_Input_Flag    = "select";
            propInfo.Prop_Max_Length    = 1000;
            propInfo.Prop_Default_Value = "";
            propInfo.Prop_Status        = 1;
            propInfo.Display_Index      = 0;
            if (isNew)
            {
                propInfo.Create_User_Id = loggingSessionInfo.UserID;
                propInfo.Create_Time    = DateTime.Now.ToString();
            }
            propInfo.Modify_User_Id = loggingSessionInfo.UserID;
            propInfo.Modify_Time    = DateTime.Now.ToString();
            string error = "";

            service.SaveProp(propInfo, ref error);
            if (!string.IsNullOrEmpty(error))
            {
                throw new APIException(error)
                      {
                          ErrorCode = 135
                      };
            }
            if (!isNew)//不是新的
            {
                string propIds = "";
                foreach (var itemInfo in propInfo.Children)//数组,更新数据
                {
                    if (!string.IsNullOrEmpty(itemInfo.Prop_Id))
                    {
                        if (propIds != "")
                        {
                            propIds += ",";
                        }
                        propIds += "'" + itemInfo.Prop_Id + "'";
                    }
                }
                //删除不在这个里面的
                service.DeletePropByIds(propIds, propInfo);
            }

            int i = 0;

            foreach (var itemInfo in propInfo.Children)//数组,更新数据
            {
                if (string.IsNullOrEmpty(itemInfo.Prop_Id))
                {
                    itemInfo.Prop_Id = Guid.NewGuid().ToString();
                }
                itemInfo.Prop_Code          = itemInfo.Prop_Name;
                itemInfo.Prop_Eng_Name      = "";
                itemInfo.Prop_Type          = "3";              //属性类型 1=组,2=属性,3=属性明细';
                itemInfo.Parent_Prop_id     = propInfo.Prop_Id; //父类id
                itemInfo.Prop_Level         = 2;
                itemInfo.Prop_Domain        = "SKU";
                itemInfo.Prop_Input_Flag    = "select";
                itemInfo.Prop_Max_Length    = 1000;
                itemInfo.Prop_Default_Value = "";
                itemInfo.Prop_Status        = 1;
                itemInfo.Display_Index      = ++i;
                service.SaveProp(itemInfo, ref error);
            }

            //如果是新建的情况
            //如果不存在属性关系(sku和属性之间的关系)
            if (!skuPropServer.CheckSkuProp(propInfo.Prop_Id))
            {
                SkuPropInfo skuPropInfo = new SkuPropInfo();
                skuPropInfo.sku_prop_id   = Utils.NewGuid();
                skuPropInfo.prop_id       = propInfo.Prop_Id;
                skuPropInfo.CustomerId    = loggingSessionInfo.ClientID;
                skuPropInfo.status        = propInfo.Prop_Status.ToString();
                skuPropInfo.display_index = propInfo.Display_Index;
                skuPropServer.AddSkuProp(skuPropInfo);
            }

            var rsp = new SuccessResponse <IAPIResponseData>(rd);

            return(rsp.ToJSON());
        }