Пример #1
0
        /// <summary>
        /// 单页栏目
        /// </summary>
        /// <param name="id">栏目ID</param>
        /// <returns></returns>
        public ActionResult ModifyPage(int id)
        {
            var _pageManager = new CategoryPageManager();
            var _page        = _pageManager.Find(g => g.CategoryID == id);

            if (_page == null)
            {
                _page = new CategoryPage()
                {
                    View = "index"
                }
            }
            ;
            return(PartialView(_page));
        }
Пример #2
0
        public ActionResult Modify(int id, FormCollection form)
        {
            Category _category = categoryManager.Find(id);

            if (_category == null)
            {
                return(View("Prompt", new Prompt()
                {
                    Title = "错误", Message = "栏目不存在!"
                }));
            }
            if (TryUpdateModel(_category, new string[] { "Type", "ParentID", "Name", "Description", "Order", "Target" }))
            {
                //检查父栏目
                if (_category.ParentID > 0)
                {
                    var _parentCategory = categoryManager.Find(_category.ParentID);
                    if (_parentCategory == null)
                    {
                        ModelState.AddModelError("ParentID", "父栏目不存在,请刷新后重新添加");
                    }
                    else if (_parentCategory.Type != CategoryType.General)
                    {
                        ModelState.AddModelError("ParentID", "父栏目不允许添加子栏目");
                    }
                    else if (_parentCategory.ParentPath.IndexOf(_category.ParentPath) >= 0)
                    {
                        ModelState.AddModelError("ParentID", "父栏目不能是其本身或其子栏目");
                    }
                    else
                    {
                        _category.ParentPath = _parentCategory.ParentPath + "," + _parentCategory.ID;
                        _category.Depth      = _parentCategory.Depth + 1;
                    }
                }
                else
                {
                    _category.ParentPath = "0";
                    _category.Depth      = 0;
                }
                //栏目基本信息保存
                Response _response = new Response()
                {
                    Code = 0, Message = "初始失败信息"
                };
                //根据栏目类型进行处理
                switch (_category.Type)
                {
                case CategoryType.General:
                    var _general = _generalManager.Find(g => g.CategoryID == id);
                    if (_general == null)
                    {
                        _general = new CategoryGeneral()
                        {
                            CategoryID = id, View = "Index", ContentView = "Index"
                        }
                    }
                    ;
                    if (TryUpdateModel(_general, new string[] { "View", "ContentTypeID", "ContentView" }))
                    {
                        _response = categoryManager.Update(_category, _general);
                    }
                    break;

                //暂不实现
                case CategoryType.Page:
                    return(View("Prompt", new Prompt()
                    {
                        Title = "暂未实现", Message = "暂未实现单页栏目修改"
                    }));

                    var _pageManager = new CategoryPageManager();
                    var _page        = _pageManager.Find(p => p.CategoryID == id);
                    if (_page == null)
                    {
                        _page = new CategoryPage()
                        {
                            CategoryID = id, View = "index"
                        }
                    }
                    ;
                    if (TryUpdateModel(_page))
                    {
                        _response = categoryManager.Update(_category, _page);
                    }
                    break;

                //暂不实现
                case CategoryType.Link:
                    return(View("Prompt", new Prompt()
                    {
                        Title = "暂未实现", Message = "暂未实现外部链接修改"
                    }));

                    var _linkManager = new CategoryLinkManager();
                    var _link        = _linkManager.Find(l => l.CategoryID == id);
                    if (_link == null)
                    {
                        _link = new CategoryLink()
                        {
                            CategoryID = id, Url = "http://"
                        }
                    }
                    ;
                    if (TryUpdateModel(_link))
                    {
                        _response = categoryManager.Update(_category, _link);
                    }
                    break;
                }
                if (ModelState.IsValid)
                {
                    if (_response.Code == 1)
                    {
                        return(View("Prompt", new Prompt()
                        {
                            Title = "修改栏目成功", Message = "修改栏目【" + _category.Name + "】成功"
                        }));
                    }
                    else
                    {
                        return(View("Prompt", new Prompt()
                        {
                            Title = "修改栏目失败", Message = "修改栏目【" + _category.Name + "】时发生系统错误,未能保存到数据库,请重试"
                        }));
                    }
                }
            }
            return(View(_category));
        }