Ejemplo n.º 1
0
        public IActionResult Add(int pid, string caname)
        {
            caname = Tool.GetSafeSQL(caname);
            string pbh = "0";

            if (pid != 0)
            {
                Model.Category pca = dal.GetModel(pid);
                if (pca.Pbh != "0")
                {
                    return(Json(new { status = "n", info = "最多只能添加二级分类!" }));
                }
                pbh = pca.Bh;
                if (dal.CalcCount($"pbh='{pca.Pbh}' and caname='{caname}'") > 0)
                {
                    return(Json(new { status = "n", info = "已有同名分类,不准增加!" }));
                }
            }
            else
            {
                if (dal.CalcCount($"pbh='0' and caname='{caname}'") > 0)
                {
                    return(Json(new { status = "n", info = "已有同名分类,不准增加!" }));
                }
            }

            string bh = dal.GenBH(pbh, 2);

            dal.Insert(new Model.Category()
            {
                CaName = caname, Pbh = pbh, Bh = bh
            });

            return(Json(new { status = "y", info = "新增分类成功!" }));
        }