//保存扩展属性 private void SaveExts(Base_Catalog cat, NameValueCollection form) { cat.Exts.Clear(); var ids = form["ExtId"].Split(','); var names = form["ExtName"].Split(','); var defaultValues = form["DefaultValue"].Split(','); var dataTypes = form["DataType"].Split(','); var maxLengths = form["MaxLength"].Split(','); //var allownulls = form["AllowNull"].Split(','); var states = form["ExtState"].Split(','); var dataSourceTypes = form["DataSourceType"].Split(','); var dataSources = form["DataSource"].Split(','); for (int i = 1; i < names.Length; i++) { if (!string.IsNullOrEmpty(names[i])) { Base_CatalogExt ext = new Base_CatalogExt { Id = CommOp.ToInt(ids[i]), CatalogId = cat.Id, Name = names[i], DefaultValue = defaultValues[i], DataType = CommOp.ToEnum <ExtDataType>(dataTypes[i]), State = states[i] == "" ? ArticleState.Published : CommOp.ToInt(states[i]), Ord = i, //AllowNull = CommOp.ToBool(allownulls[i] == "on" ? true : false), MaxLength = CommOp.ToInt(maxLengths[i]), DataSourceType = CommOp.ToEnum <ExtDataSourceType>(dataSourceTypes[i]), DataSource = dataSources[i] }; cat.Exts.Add(ext); } } }
/// <summary> /// 删除一个目录(带删除目录中的子目录以及文件) /// </summary> /// <param name="catalogId">目录Id</param> /// <returns></returns> public bool DeleteCatalog(int catalogId) { //获得所有的子目录 List <ResourceCatalogInfo> catList = new List <ResourceCatalogInfo>(); catList.Add(new ResourceCatalogInfo { Id = catalogId, }); catList.AddRange(GetDescendantCatalogs(catalogId)); //先从最低级的目录开始删除数据 for (int i = catList.Count() - 1; i >= 0; i--) { //如果目录中有文件,必须先删除文件再删除目录 var files = GetFilesInCatalog(catList[i].Id); if (files != null) { foreach (var file in files) { DeleteFile(file.Id); } } Base_Catalog c = Catalog.GetById(catList[i].Id); bool b = Catalog.Remove(c); } return(true); }
/// <summary> /// 删除目录 /// 修改:[2017-01-16/汪敏] /// </summary> /// <param name="catalogId">目录ID</param> /// <returns></returns> public JsonResult DeleteCatalog(int catalogId) { //判断是否用户的根目录 Base_Catalog uc = _resourceFileService.Catalog.GetById(catalogId); //if (uc.ParentId == _resourceFileService.GetFileCatalogRootId()) //{ // return JsonTipsLang("error", "RootDirectory_Cannot_Delete"); //用户的根目录不能删除 //} if (uc == null) { return(JsonTipsLang("error", "Directory_IsNull")); //选择的目录不存在 } var catalogsInfo = _resourceFileService.GetChildrenCatalogs(catalogId); if (_resourceFileService.DeleteCatalog(catalogId)) { return(JsonTips("success", JStr.SuccessDeleted)); } else { return(JsonTips("error", JStr.DeleteFailed)); } }
/// <summary> /// 取得根目录 /// 修改:[2017-01-16/汪敏] /// </summary> /// <returns></returns> public Base_Catalog GetUserRootCatalog(int userId) { //Base_Catalog uc = Catalog.GetAll().FirstOrDefault(c => c.OwnerType == CatalogOwnerType.User // && c.OwnerId == userId); Base_Catalog uc = Catalog.GetAll().FirstOrDefault(c => c.OwnerType == CatalogOwnerType.User && c.OwnerId == userId && c.ParentId == SystemTypes.UserFiles.Id); if (uc == null) { uc = new Base_Catalog() { OwnerId = userId, OwnerType = CatalogOwnerType.User, Name = AppManager.Instance.UserManager.GetById(userId.ToString()).Name, State = ArticleState.Published, ParentId = SystemTypes.UserFiles.Id }; Catalog.Save(uc); } else { if (uc.State != ArticleState.Published) { uc.State = ArticleState.Published; Catalog.Save(uc); } } return(uc); }
/// <summary> /// 返回要编辑的功能的详细信息 /// </summary> /// <param name="id">要编辑的树结点ID</param> /// <returns>功能对象的的Json</returns> public virtual JsonResult Edit(int id) { Base_Catalog cat = null; cat = SiteManager.Catalog.GetById(id) ?? SiteManager.Catalog.Create(); // Session["EditingFunction"] = func; return(JsonTips(cat, JsonRequestBehavior.AllowGet)); }
//[ValidateAntiForgeryToken] public virtual JsonResult Edit(Base_Catalog cat) { if (Request.Form["ExtId"] != null) { SaveExts(cat, Request.Form); } SiteManager.Catalog.Save(cat); return(JsonTips("success", JStr.SuccessSaved, JStr.SuccessSaved0, (object)cat.Id, cat.Name)); }
/// <summary> /// 映射 /// </summary> /// <param name="a"></param> /// <returns></returns> private ResourceCatalogInfo ToResourceCatalogInfo(Base_Catalog c) { ResourceCatalogInfo d = new ResourceCatalogInfo(); d.Id = c.Id; d.ParentId = (c.ParentId == null) ? 0 : c.ParentId.Value; d.Name = c.Name; d.OwnerId = c.OwnerId; d.OwnerType = d.OwnerType; return(d); }
/// <summary> /// 编辑页面 /// </summary> /// <param name="caId">栏目文章ID</param> /// <returns>用户编辑页面</returns> public virtual ActionResult Edit(int caId = 0) { var ca = (caId > 0) ? _resourceFileService.Article.GetById(caId) : _resourceFileService.Article.CreateByCatalog(CatalogId); _innerCatalogId = ca.CatalogId; Session["Editing_" + _innerCatalogId] = ca; ViewBag.ShowBreadCrumb = false; Base_Catalog cat = SiteManager.Catalog.GetById(_innerCatalogId); string catName = cat == null ? null : cat.Name; ca.CheckExts(); return(View(ca.Article)); }
/// <summary> /// 更新一个目录对象 /// </summary> /// <param name="ResourceCatalogInfo">目录</param> /// <returns></returns> public ResourceCatalogInfo UpdateCatalog(ResourceCatalogInfo info) { Base_Catalog c = Catalog.GetById(info.Id); if (c == null) { return(null); } c.ParentId = info.ParentId; c.Name = info.Name; Base_Catalog c2 = Catalog.Save(c); var returnInfo = ToResourceCatalogInfo(c2); return(returnInfo); }
/// <summary> /// 获取文件的目录 /// </summary> /// <param name="fileId">文件ID</param> /// <returns></returns> public ResourceCatalogInfo GetCatalogOfFile(int fileId) { var a = _article.GetById(fileId); if (a == null) { return(null); } ResourceFileInfo info = ToResourceFileInfo(a); int catalogId = info.CatalogId; Base_Catalog c = Catalog.GetById(catalogId); var rc = ToResourceCatalogInfo(c); return(rc); }
/// <summary> /// 目录管理的主界面 /// </summary> /// <param name="root">管理的目录树的根结点ID或名称</param> /// <returns>主界面视图</returns> public ActionResult Index(string root = "") { InitMenuBar(); Base_Catalog rootCat = null; if (CommOp.IsNumeric(root)) { rootCat = SiteManager.Catalog.GetById(CommOp.ToInt(root)); } if (rootCat == null && !root.IsEmpty()) { rootCat = SiteManager.Catalog.GetByName(root); } if (rootCat == null) { rootCat = SiteManager.Get <Base_Catalog>(); } return(View(rootCat)); }
/// <summary> /// 保存一个目录对象 /// </summary> /// <param name="ResourceCatalogInfo">目录</param> /// <returns></returns> public ResourceCatalogInfo SaveCatalog(ResourceCatalogInfo info) { Base_Catalog c = new Base_Catalog { Name = info.Name, Ord = 1, State = ArticleState.Static, EditTime = TimeHelper.ServerTime, OwnerId = info.OwnerId, OwnerType = info.OwnerType }; if (info.ParentId > 0) { c.ParentId = info.ParentId; } Base_Catalog c2 = Catalog.Save(c); var returnInfo = ToResourceCatalogInfo(c2); return(returnInfo); }