/// <summary> /// 链接栏目 /// </summary> /// <param name="id">栏目ID</param> /// <returns></returns> public ActionResult ModifyLink(int id) { var _linkManager = new CategoryLinkServices(); var _link = _linkManager.Find(id); if (_link == null) { _link = new CategoryLink() { Url = "http://" } } ; return(PartialView(_link)); }
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.CategoryID; _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 _generalManager = new CategoryGeneralServices(); var _general = _generalManager.Find(id); if (_general == null) { _general = new CategoryGeneral() { CategoryID = id, View = "Index", ContentView = "Index" } } ; if (TryUpdateModel(_general)) { _response = categoryManager.Update(_category, _general); } break; case CategoryType.Page: var _pageManager = new CategoryPageServices(); var _page = _pageManager.Find(id); if (_page == null) { _page = new CategoryPage() { CategoryID = id, View = "index" } } ; if (TryUpdateModel(_page)) { _response = categoryManager.Update(_category, _page); } break; case CategoryType.Link: var _linkManager = new CategoryLinkServices(); var _link = _linkManager.Find(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)); }