Beispiel #1
0
        public ActionResult AdminCategoryEdit(CategoryModel model)
        {
            if (ModelState.IsValid)
            {
                var catelist = MyService.GetFCategoryList();
                var newlst   = new List <CategoryModel>();
                var newlst2  = new List <CategoryModel>();
                var category = new CategoryModel
                {
                    CateId   = model.CateId,
                    CateName = model.CateName,
                    IsIndex  = model.IsIndex,
                    IsNav    = model.IsNav,
                    ListNum  = model.ListNum,
                    ParentId = model.ParentId,
                    ReName   =
                        string.IsNullOrWhiteSpace(model.ReName) ? string.Empty : model.ReName,
                    CustomView =
                        string.IsNullOrWhiteSpace(model.CustomView)
                                               ? string.Empty
                                               : model.CustomView,
                    HomePageKey =
                        string.IsNullOrWhiteSpace(model.HomePageKey)
                                               ? string.Empty
                                               : model.HomePageKey
                };
                if (category.IsIndex && category.HomePageKey == string.Empty && category.Type < 3)
                {
                    category.HomePageKey = "cate" + category.CateId;
                }
                category.ReplyPermit = model.ReplyPermit;
                category.Status      = model.Status;
                category.Type        = model.Type;
                category.Description = WebUtils.MyString(model.Description);

                category.OrderId  = catelist.Count() + 1;
                category.SubCount = 0;
                category.Path     = "0";
                var isPathChange = false;

                foreach (var c in catelist)
                {
                    if (category.CateId == c.CateId)
                    {
                        if (category.ParentId == c.ParentId)
                        {
                            category.OrderId  = c.OrderId;
                            category.SubCount = c.SubCount;
                            category.Path     = c.Path;
                        }
                        newlst.Add(category);
                    }
                    else
                    {
                        newlst.Add(c);
                    }
                }

                if (category.Path == "0")
                {
                    isPathChange = true;
                    newlst       = RefreshCateList(newlst);
                    GetNewCategoryList(newlst, ref newlst2, 0);
                }
                else
                {
                    newlst2 = newlst;
                }
                SaveCateInfo(newlst2);
                if (isPathChange)
                {
                    var newcategory = MyService.GetCategoryById(model.CateId);
                    MyService.BatchUpdateArticlePath(model.CateId, newcategory.Path);
                }
            }
            else
            {
                return(Content("error", "text/html;charset=UTF-8"));
            }

            return(Content(string.Empty, "text/html;charset=UTF-8"));
        }