コード例 #1
0
        public ActionResult AddProduct()
        {
            string productNoes = Request["productNoes"];
            string topicNo     = Request["topicId"];
            string flag        = Request["flag"];

            //需要根据具体的需求进行改造
            if (string.IsNullOrEmpty(productNoes))
            {
                return(Json(new { rs = "Error", msg = "没有要添加的商品" }));
            }
            if (string.IsNullOrEmpty(topicNo))
            {
                return(Json(new { rs = "Error", msg = "专题编号错误" }));
            }
            if (flag == "pl")//批量添加的商品 以回车符号分隔的,这个需要处理,手动添加的以逗号分割的则不用处理
            {
                //处理成以逗号分隔就OK
                productNoes = productNoes.Replace("\n\r", ",").Replace("\r\n", ",").Replace("\r", ",").Replace("\n", ",");
            }



            //判断添加商品是否存在,存在则返回错误 不存在则添加
            SWfsTopicService           topicServ = new SWfsTopicService();
            List <SWfsTopicProductRef> rs        = topicServ.GetSWfsTopicProductList(productNoes, topicNo);

            if (null != rs && rs.Count > 0)
            {
                string tmp = string.Empty;
                foreach (var item in rs)
                {
                    tmp += item.ProductNo + ",";
                }
                return(Json(new { rs = "Error", msg = "商品:" + tmp + "已经存在" }));
            }
            else
            {
                List <string> pNoes = productNoes.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
                if (null == pNoes || pNoes.Count <= 0)
                {
                    return(Json(new { rs = "Error", msg = "没有要添加的商品" }));
                }
                SWfsTopicProductRef model;
                foreach (var item in pNoes)
                {
                    model                = new SWfsTopicProductRef();
                    model.ProductNo      = item;
                    model.TopicNo        = topicNo;
                    model.OrderFlag      = 999;
                    model.TopicProductNo = topicNo + item;
                    topicServ.AddProductNo(model);
                }
                return(Json(new { rs = "Success", msg = "添加成功!" }));
            }
        }
コード例 #2
0
 public void AddProductNo(SWfsTopicProductRef model)
 {
     DapperUtil.Insert <SWfsTopicProductRef>(model);
 }