public int CreateFile(string FileID, string FileName, string FileParentID)
        {
            var      v     = db.OS_Files.Where(p => p.ID == new Guid(FileParentID));
            OS_Files model = new OS_Files();

            model.ID        = new Guid(FileID);
            model.Name      = FileName;
            model.ParentID  = new Guid(FileParentID);
            model.ParentIDs =
                v.Count() > 0 ?
                (v.First().ParentIDs + FileParentID + "|") :
                ("|" + FileParentID + "|");
            model.state        = 0;
            model.ModifiedDate = model.CreatedDate = DateTime.Now;
            db.OS_Files.Add(model);
            return(db.SaveChanges());
        }
        /// <summary>
        /// 递归复制文件夹集
        /// </summary>
        /// <param name="list">集合</param>
        /// <param name="FileID">老文件夹ID</param>
        /// <param name="newFileID">新文件夹ID</param>
        /// <param name="oldParentIDs">老文件夹父级IDs</param>
        /// <param name="newParentIDs">新文件夹父级IDs</param>
        void ForeachCopyFile(List <OS_Files> list, string FileID, string newFileID, string oldParentIDs, string newParentIDs)
        {
            var v = list.Where(p => p.ParentID == new Guid(FileID));

            foreach (var _v in v)
            {
                OS_Files model = new OS_Files();
                model.ID           = Guid.NewGuid();
                model.Name         = _v.Name;
                model.ParentID     = new Guid(newFileID);
                model.ParentIDs    = _v.ParentIDs.Replace(oldParentIDs, newParentIDs) + newFileID + "|";
                model.state        = 0;
                model.ModifiedDate = model.CreatedDate = DateTime.Now;
                db.OS_Files.Add(model);
                ForeachCopyFile(list, _v.ID.ToString(), model.ID.ToString(), _v.ParentIDs, model.ParentIDs);
            }
        }
 public int AddFile(string FileID, string FileName, string FileParentID, string FileType)
 {
     var v = db.OS_Files.Where(p => p.ID == new Guid(FileParentID));
     OS_Files model = new OS_Files();
     model.ID = new Guid(FileID);
     model.Name = FileName;
     model.ParentID = new Guid(FileParentID);
     model.ParentIDs =
         v.Count() > 0 ?
         (v.First().ParentIDs + FileParentID + "|") :
         ("|" + FileParentID + "|");
     model.Type = FileType;
     model.state = 1;
     model.ModifiedDate = model.CreatedDate = DateTime.Now;
     db.OS_Files.Add(model);
     return db.SaveChanges();
 }
 public int CopyFile(string FileID, string FileParentID)
 {
     var v = from p in db.OS_Files
             where p.ID == new Guid(FileID) || p.ParentIDs.IndexOf("|" + FileID + "|") > -1 || p.ID == new Guid(FileParentID)
             select p;
     if (v.Count() > 0)
     {
         var _v = v.Where(p => p.ID == new Guid(FileID));
         OS_Files model = new OS_Files();
         model.ID = Guid.NewGuid();
         model.Name = _v.First().Name;
         model.ParentID = new Guid(FileParentID);
         model.ParentIDs = v.Where(p => p.ID == new Guid(FileParentID)).First().ParentIDs + FileParentID + "|";
         model.state = 0;
         model.ModifiedDate = model.CreatedDate = DateTime.Now;
         db.OS_Files.Add(model);
         ForeachCopyFile(v.ToList(), FileID, model.ID.ToString(), v.First().ParentIDs, model.ParentIDs);
         db.SaveChanges();
         return 1;
     }
     return 0;
 }
        public int CopyFile(string FileID, string FileParentID)
        {
            var v = from p in db.OS_Files
                    where p.ID == new Guid(FileID) || p.ParentIDs.IndexOf("|" + FileID + "|") > -1 || p.ID == new Guid(FileParentID)
                    select p;

            if (v.Count() > 0)
            {
                var      _v    = v.Where(p => p.ID == new Guid(FileID));
                OS_Files model = new OS_Files();
                model.ID           = Guid.NewGuid();
                model.Name         = _v.First().Name;
                model.ParentID     = new Guid(FileParentID);
                model.ParentIDs    = v.Where(p => p.ID == new Guid(FileParentID)).First().ParentIDs + FileParentID + "|";
                model.state        = 0;
                model.ModifiedDate = model.CreatedDate = DateTime.Now;
                db.OS_Files.Add(model);
                ForeachCopyFile(v.ToList(), FileID, model.ID.ToString(), v.First().ParentIDs, model.ParentIDs);
                db.SaveChanges();
                return(1);
            }
            return(0);
        }
 /// <summary>
 /// 递归复制文件夹集
 /// </summary>
 /// <param name="list">集合</param>
 /// <param name="FileID">老文件夹ID</param>
 /// <param name="newFileID">新文件夹ID</param>
 /// <param name="oldParentIDs">老文件夹父级IDs</param>
 /// <param name="newParentIDs">新文件夹父级IDs</param>
 void ForeachCopyFile(List<OS_Files> list, string FileID, string newFileID, string oldParentIDs, string newParentIDs)
 {
     var v = list.Where(p => p.ParentID == new Guid(FileID));
     foreach (var _v in v)
     {
         OS_Files model = new OS_Files();
         model.ID = Guid.NewGuid();
         model.Name = _v.Name;
         model.ParentID = new Guid(newFileID);
         model.ParentIDs = _v.ParentIDs.Replace(oldParentIDs, newParentIDs) + newFileID + "|";
         model.state = 0;
         model.ModifiedDate = model.CreatedDate = DateTime.Now;
         db.OS_Files.Add(model);
         ForeachCopyFile(list, _v.ID.ToString(), model.ID.ToString(), _v.ParentIDs, model.ParentIDs);
     }
 }