Example #1
0
        public ActionResult Prop(FormCollection fc)
        {
            int    leafCid = Utils.StrToInt(fc["leafCid"], 0);
            int    propId  = Utils.StrToInt(fc["propId"], 0);
            bool   error   = true;
            string msg     = string.Empty;
            string action  = fc["action"] ?? string.Empty;

            try
            {
                if (action.Equals("deleteprop", StringComparison.OrdinalIgnoreCase))
                {
                    //删除
                    int i = ProductPropService.Delete(propId, leafCid);
                    if (i > 0)
                    {
                        error = false;
                    }
                }
                else if (action.Equals("addbatchprops", StringComparison.OrdinalIgnoreCase))
                {
                    //批量保存属性名
                    string propsName = fc["name"] ?? string.Empty;
                    propsName = propsName.Replace("\r", string.Empty).Replace("\n", "|");
                    string[] propsNameArr = propsName.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var name in propsNameArr)
                    {
                        ProductPropService.Create(new ProductPropInfo()
                        {
                            CategoryId = leafCid,
                            Name       = name
                        });
                    }
                    error = false;
                }
                else
                {
                    //添加或编辑
                    string propName = fc["name"] ?? string.Empty;

                    var model = ProductPropService.Create(new ProductPropInfo()
                    {
                        CategoryId = leafCid,
                        Id         = propId,
                        Name       = propName
                    });
                    if (model.Id > 0)
                    {
                        error = false;
                    }
                }
            }
            catch (Exception ex)
            {
                msg = ex.ToString();
            }
            return(Json(new { error = error, msg = msg }));
        }
Example #2
0
        /// <summary>
        /// 异步回调地址
        /// </summary>
        /// <returns></returns>
        public ActionResult Ajax()
        {
            string action = CECRequest.GetQueryString("action");

            if (action.Equals("childcid", StringComparison.OrdinalIgnoreCase))
            {
                //获得子分类
                IList <ShortCategoryInfo> list = new List <ShortCategoryInfo>();
                int cid      = CECRequest.GetQueryInt("cid", 0);
                var tempList = CategoryService.ListByParentId(cid);
                foreach (var item in tempList)
                {
                    list.Add(new ShortCategoryInfo()
                    {
                        ParentId = item.ParentId,
                        Id       = item.Id,
                        Name     = item.Name.Replace('"', '”')
                    });
                }
                return(Json(list, JsonRequestBehavior.AllowGet));
            }
            if (action.Equals("props", StringComparison.OrdinalIgnoreCase))
            {
                //获得属性列表
                int cid = CECRequest.GetQueryInt("cid", 0);
                List <ProductPropInfo> list = new List <ProductPropInfo>();
                list = ProductPropService.List(cid);
                foreach (var item in list)
                {
                    item.Name  = item.Name.Replace('"', '”');
                    item.Value = item.Value.Replace('"', '”');
                }
                return(Json(list, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { }));
        }