Example #1
0
        public HttpResponseBase SaveProductCategorySet()
        {
            string[] bids = Request.Params["brandids"].Split('|');
            string categoryid = Request.Params["categoryid"];

            string[] pids = Request.Params["productids"].Split('|');
            string proIds = string.Empty;//保存已經存在于categorset中的product
            string resultStr = "{success:false}";
            try
            {
                for (int i = 0; i < bids.Length; i++)
                {
                    if (bids[i].ToString() != "" && pids[i].ToString() != "")
                    {
                        ProductCategorySetMgr _categorySetMgr = new ProductCategorySetMgr(connectionString);
                        ProductCategorySet pcs = new ProductCategorySet();

                        pcs.Brand_Id = Convert.ToUInt32(bids[i]);
                        pcs.Category_Id = Convert.ToUInt32(categoryid);
                        pcs.Product_Id = Convert.ToUInt32(pids[i]);
                        List<ProductCategorySet> queryList = _categorySetMgr.Query(pcs);
                        if (queryList.Count == 0)//該類別下不存在該商品時才新增
                        {
                            _categorySetMgr.Insert(pcs);
                        }
                        else
                        {
                            proIds += queryList[0].Product_Id;
                            if (i != bids.Length - 1)
                            {
                                proIds += ",";

                            }
                        }

                    }
                }

                resultStr = "{success:true,\"proIds\":\"" + proIds + "\"}";
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
            }

            this.Response.Clear();
            this.Response.Write(resultStr);
            this.Response.End();
            return this.Response;
        }