コード例 #1
0
 public ActionResult Edit(ColumnInfo oldModel)
 {
     if (oldModel.Id == 0)
     {
         return(RedirectToAction("List"));
     }
     if (ModelState.IsValid)
     {
         ColumnService.Create(oldModel);
         ViewBag.Msg = "更新成功,<a href=\"list\">返回</a>";
     }
     return(View());
 }
コード例 #2
0
        public ActionResult List()
        {
            if (Request.HttpMethod.ToUpper() == "POST")
            {
                //POST
                var action = CECRequest.GetFormString("action").ToLower();
                if (action == "addparent")
                {
                    //添加父节点
                    string name = CECRequest.GetFormString("txtParentName");
                    if (string.IsNullOrEmpty(name))
                    {
                        ModelState.AddModelError("PNAMEEMPTY", "根栏目名称不能为空");
                    }
                    if (ModelState.IsValid)
                    {
                        //Insert
                        ColumnService.Create(new ColumnInfo()
                        {
                            Name      = name,
                            Alias     = string.Empty,
                            ParentId  = 0,
                            RootId    = 0,
                            IsDeleted = false,
                            ParentIds = "0",
                            Sort      = 999999
                        });
                        ViewBag.Msg = "根栏目添加成功";
                    }
                }
                if (action == "addchild")
                {
                    //添加子节点
                    string name = CECRequest.GetFormString("txtChildName");
                    if (string.IsNullOrEmpty(name))
                    {
                        ModelState.AddModelError("CNAMEEMPTY", "子栏目名称不能为空");
                    }
                    if (ModelState.IsValid)
                    {
                        //保存
                        int parentId         = Utils.StrToInt(CECRequest.GetFormString("select_column"), 0);
                        var parentColumnInfo = ColumnService.GetById(parentId);
                        if (parentColumnInfo.Id > 0)
                        {
                            //RootId
                            int rootId = parentColumnInfo.RootId;
                            if (parentColumnInfo.ParentId == 0)
                            {
                                //说明是根分类
                                rootId = parentColumnInfo.Id;
                            }
                            //ParentIds
                            string parentIds = string.Format("{0},{1}", parentColumnInfo.ParentIds, parentColumnInfo.Id);

                            ColumnService.Create(new ColumnInfo()
                            {
                                Alias     = string.Empty,
                                IsDeleted = false,
                                Name      = name,
                                ParentId  = parentId,
                                ParentIds = parentIds,
                                RootId    = rootId,
                                Sort      = 999999
                            });
                            ViewBag.Msg = "子栏目添加成功";
                        }
                    }
                }
            }

            //创建下拉列表
            var allColumn    = ColumnService.List().ToList();
            var dropdownList = new List <ColumnInfo>();

            ColumnService.BuildListForTree(dropdownList, allColumn, 0);
            ViewBag.DropDownList = dropdownList;

            ViewBag.ColumnListHtml = _BuildColumnList(allColumn, 0);


            return(View());
        }