Пример #1
0
        public string Rename(int folderId, string newFolderName)
        {
            string success = "";

            try
            {
                string oldName;
                using (var db = new OggleBoobleMySqlContext())
                {
                    var dbSourceFolder = db.CategoryFolders.Where(f => f.Id == folderId).FirstOrDefault();
                    oldName = dbSourceFolder.FolderName;
                    string parentPath = Helpers.GetParentPath(folderId);
                    string ftpPath    = ftpHost + dbSourceFolder.RootFolder + hostingPath + parentPath + oldName;

                    string[] serverSideFiles = FtpUtilies.GetFiles(ftpPath);
                    string   fileNameGuid    = "";
                    string   newFileName     = "";
                    foreach (string serverSideFile in serverSideFiles)
                    {
                        fileNameGuid = serverSideFile.Substring(serverSideFile.LastIndexOf("_"));
                        newFileName  = newFolderName + fileNameGuid;
                        FtpUtilies.RenameFile(ftpPath + "/" + serverSideFile, newFileName);
                    }
                    success = FtpUtilies.RenameFolder(ftpPath, newFolderName);
                    if (success == "ok")
                    {
                        dbSourceFolder.FolderName = newFolderName;
                        db.SaveChanges();
                    }
                }
                //if (success == "ok")
                //{
                //    using (var mdb = new OggleBoobleMySqlContext())
                //    {
                //        var mySqlCategoryFolder = mdb.CategoryFolders.Where(f => f.Id == folderId).FirstOrDefault();
                //        mySqlCategoryFolders.FolderName = newFolderName;
                //        mdb.SaveChanges();
                //    }
                //}
            }
            catch (Exception ex)
            {
                success = Helpers.ErrorDetails(ex);
            }
            return(success);
        }
Пример #2
0
        private string FtpMove(string currentFileName, MoveCopyImageModel model)
        {
            string success;
            string linkId = model.LinkId;

            using (var db = new OggleBoobleMySqlContext())
            {
                ImageFile dbImageFile = db.ImageFiles.Where(i => i.Id == linkId).FirstOrDefault();
                if (dbImageFile == null)
                {
                    return("link [" + linkId + "] not found");
                }
                //imageLinkId = dbImageFile.Id;

                // ? physcially more and rename .jpg
                CategoryFolder dbSourceFolder      = db.CategoryFolders.Where(f => f.Id == model.SourceFolderId).First();
                CategoryFolder dbDestinationFolder = db.CategoryFolders.Where(f => f.Id == model.DestinationFolderId).First();
                //string currentFileName = dbImageFile.FileName;
                string newFileName        = dbSourceFolder.FolderName + "_" + linkId;
                string destinationFtpPath = ftpHost + dbDestinationFolder.RootFolder + ".ogglebooble.com/" + Helpers.GetParentPath(model.DestinationFolderId) + dbDestinationFolder.FolderName;
                string sourceFtpPath      = ftpHost + dbSourceFolder.RootFolder + ".ogglebooble.com/" + Helpers.GetParentPath(model.SourceFolderId) + newFileName;

                if (!FtpUtilies.DirectoryExists(destinationFtpPath))
                {
                    FtpUtilies.CreateDirectory(destinationFtpPath);
                }

                success = FtpUtilies.MoveFile(sourceFtpPath + "/" + dbImageFile.FileName, destinationFtpPath + "/" + newFileName);
                if (success == "ok")
                {
                    #region move file on local drive
                    string localDestinationPath = "";
                    try
                    {
                        string localServerPath = "F:/Danni/";
                        string localSourcePath = localServerPath + Helpers.GetLocalParentPath(model.SourceFolderId) + dbSourceFolder.FolderName + "/" + dbImageFile.FileName;
                        //dbSourceFolder.FolderName + "_" + dbImageLink.Id + extension;
                        localDestinationPath = localServerPath + Helpers.GetLocalParentPath(model.DestinationFolderId) + dbDestinationFolder.FolderName;
                        FileInfo      localFile     = new FileInfo(localSourcePath);
                        DirectoryInfo directoryInfo = new DirectoryInfo(localDestinationPath);
                        if (!directoryInfo.Exists)
                        {
                            directoryInfo.Create();
                        }
                        localFile.MoveTo(localDestinationPath + "/" + newFileName);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine("move file on local drive : " + Helpers.ErrorDetails(ex) + " " + localDestinationPath);
                    }
                    #endregion

                    //2. update ImageFile
                    //string linkPrefix = "http://" + dbDestinationFolder.RootFolder + ".ogglebooble.com/";
                    //newInternalLink = linkPrefix + Helpers.GetParentPath(model.DestinationFolderId) + dbDestinationFolder.FolderName + "/" + newFileName;
                    //var goDaddyrow = db.ImageLinks.Where(g => g.Id == dbImageLink.Id).FirstOrDefault();
                    var oldCatImageLink = db.CategoryImageLinks
                                          .Where(c => c.ImageCategoryId == model.SourceFolderId && c.ImageLinkId == dbImageFile.Id).First();
                    db.CategoryImageLinks.Add(new MySqlDataContext.CategoryImageLink()
                    {
                        ImageCategoryId = model.DestinationFolderId,
                        ImageLinkId     = dbImageFile.Id,
                        SortOrder       = oldCatImageLink.SortOrder
                    });
                    db.SaveChanges();
                    if (model.Mode == "Move")
                    {
                        db.CategoryImageLinks.Remove(oldCatImageLink);
                    }
                    db.SaveChanges();
                }
                return(success);
            }
        }