コード例 #1
0
ファイル: FoldersController.cs プロジェクト: jarradm/PAWA
        public void createFolder(string FolderName, int? InFolderID)
        {
            PAWAContext db = new PAWAContext();
            if (FolderName == null)
            {
                FolderName = "Folder";
            }
            if (InFolderID == -1)
            {
                InFolderID = null;
            }

            var newFolder = new PAWA.Models.Folder
            {
                CreateDateTime = System.DateTime.Now,
                FolderName = FolderName,
                InFolderID = InFolderID,
                UserID = WebSecurity.CurrentUserId,

                //FolderID auto?

            };

            db.Folders.Add(newFolder);
            db.SaveChanges();
        }
コード例 #2
0
ファイル: DeleteFolder.cs プロジェクト: jarradm/PAWA
        public int deleteFolderChain(Folder DeleteMe)
        {
            PAWAContext db = new PAWAContext();
            AlbumGrid toolbelt = new AlbumGrid(dbContext);
            IEnumerable<Folder> listOfInternalFolders = toolbelt.GetFolders(DeleteMe.FolderID);
            IEnumerable<PAWA.Models.File> listOfInternalFiles = toolbelt.GetFiles(DeleteMe.FolderID);

            int nFolderDel = 0;
            int lengthOfInternalFolders;

            if (listOfInternalFolders.Count() > 0)
            {
                lengthOfInternalFolders = listOfInternalFolders.Count();
            }
            else
            {
                lengthOfInternalFolders = 0;
            }

            for (int i = 0; i < lengthOfInternalFolders; i++)
            {
                Folder delFolder = listOfInternalFolders.ElementAt(0);
                nFolderDel += deleteFolderChain(delFolder);
            }

            deleteMultipleFiles(listOfInternalFiles);
            dbContext.Folders.Remove(DeleteMe);
            dbContext.SaveChanges();
            return nFolderDel;
        }
コード例 #3
0
ファイル: FoldersController.cs プロジェクト: jarradm/PAWA
        public ActionResult Create(string FolderName, int InFolderID)
        {
            Folder newFolder = new Folder();
            newFolder.UserID = WebSecurity.CurrentUserId;
            newFolder.FolderName = FolderName;
            newFolder.InFolderID = InFolderID;
            newFolder.CreateDateTime = DateTime.Now;

            return PartialView();
        }
コード例 #4
0
ファイル: FolderRepository.cs プロジェクト: jarradm/PAWA
 public Folder Add(Folder item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     item.FolderID = _nextId++;
     item.CreateDateTime = DateTime.Now;
     folders.Add(item);
     return item;
 }
コード例 #5
0
ファイル: FolderRepository.cs プロジェクト: jarradm/PAWA
 public bool Update(Folder item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     int index = folders.FindIndex(p => p.FolderID == item.FolderID);
     if (index == -1)
     {
         return false;
     }
     folders.RemoveAt(index);
     folders.Add(item);
     return true;
 }
コード例 #6
0
ファイル: Tools.cs プロジェクト: jarradm/PAWA
 /// <summary>
 /// Returns 1 if the subfolder is within the directory tree of the parent folder. Returns 0 if root folder . If the subfolder is in a nonconventional loop(root folder is missing), the return is -1.
 /// </summary>
 /// <param name="subfolder">Folder that is presumed to be a child of the parent folder</param>
 /// <param name="parentFolder">folder that is persumed to contain the sub folder</param>
 /// <returns></returns>
 public int isSubfolder(Folder subfolder, Folder parentFolder)
 {
     int _RootID = 0;
     if (subfolder.FolderID == _RootID) { return _RootID; }
     int returnValue = -1;
     if (subfolder != null && parentFolder != null && parentFolder.UserID == subfolder.UserID)
     {
         //Folder subsParent? = getFolder(subfolder.UserID, subfolder.InFolderID);
         Folder testSubFolder = getFolder(subfolder.UserID, subfolder.FolderID);
         Folder testParentFolder = getFolder(parentFolder.UserID, parentFolder.FolderID);
         bool hasNotReachedRoot = true;
         //int inIndex = Convert.ToInt32(destinationFolder);
         if (findInfinateParentLoop(subfolder) == -1)
         {
             while ((hasNotReachedRoot = (testSubFolder.FolderID != _RootID)) && (testSubFolder.FolderID != testParentFolder.FolderID))
             {
                 testSubFolder = getFolder(testSubFolder.UserID, testSubFolder.InFolderID);
             }
             if (hasNotReachedRoot) { returnValue = 1; } else { returnValue = 0; }
         }
         else { returnValue = -1; }
     }
     return returnValue;
 }
コード例 #7
0
ファイル: Tools.cs プロジェクト: jarradm/PAWA
        ///<summary>
        /// Returns the specific Folder, given the
        /// Folder ID and the User ID.
        ///</summary>
        /// <param name="userID">ID of the user to witch the folder pertains.</param>
        /// <param name="folderID">ID of the folder that is being fetched.</param>
        /// <returns>Returns the requested folder. </returns>
        public PAWA.Models.Folder getFolder(int userID, int? folderID)
        {
            //open db connection
            //db = new PAWAContext();
            /// WARNING !!!
            ///  IF db has Zero index, change conditional from "<=" to "<"
            if (userID <= 0) { userID = 1; } // Assumption handle: User id is always greater then zero
            if (folderID <= 0) { folderID = null; } // No folder less then zero (considered null)
            var folders = from f in db.Folders where (f.FolderID == folderID || (f.FolderID == null && folderID == null)) && f.UserID == userID select f;
            Folder returnFolder;
            if (folders.Count() > 0) { returnFolder = folders.FirstOrDefault(); } else { returnFolder = new Folder(); }

            return returnFolder;
        }
コード例 #8
0
ファイル: Tools.cs プロジェクト: jarradm/PAWA
        public int findInfinateParentLoop(Folder testFolderIn)
        {
            int _RootID = 0;
            bool hasNotReachedRoot = true;
            int i = -1;

            if (testFolderIn != null)
            {
                Folder testFolder = getFolder(testFolderIn.UserID, testFolderIn.FolderID);
                //int inIndex = Convert.ToInt32(destinationFolder);
                IList<int> folderIDChain = new List<int> { };
                while ((hasNotReachedRoot = (testFolder.FolderID != _RootID)) && i <= 0)
                {
                    //check every list item in folderIDChain to see if the folder id has already been seen
                    int? c = folderIDChain.Count;
                    bool noLoopDetected = true;
                    for (i = (int)c; i > 1 && (noLoopDetected = folderIDChain.ElementAt(i - 1) != testFolder.FolderID); i--) { }
                    if (noLoopDetected == false) { return folderIDChain.ElementAt((int)c - 1); }
                    folderIDChain.Add(testFolder.FolderID);
                    testFolder = getFolder(testFolder.UserID, testFolder.InFolderID);
                }
            }
            return -1;
        }