// file operation public bool UpdateFile(string fileUD, string friendlyName, string fileLocation, string fileExtension, string thumbnailLocation, int fileSize, out string returnUD) { returnUD = string.Empty; using (FrameworkEntities context = CreateContext()) { try { Files _file = context.Files.FirstOrDefault(o => o.FileUD == fileUD); if (_file == null) { _file = new Files(); _file.FileUD = System.Guid.NewGuid().ToString().ToLower().Replace("-", ""); context.Files.Add(_file); } _file.FriendlyName = friendlyName; _file.FileLocation = fileLocation; _file.FileExtension = fileExtension; _file.ThumbnailLocation = thumbnailLocation; _file.FileSize = fileSize; context.SaveChanges(); returnUD = _file.FileUD; return(true); } catch { return(false); } } }
public bool RemoveFile(string fileUD) { using (FrameworkEntities context = CreateContext()) { try { Files _file = context.Files.FirstOrDefault(o => o.FileUD == fileUD); if (_file != null) { context.Files.Remove(_file); context.SaveChanges(); } return(true); } catch { return(false); } } }
public bool RemoveImageFile(string fileUD) { Library.FileHelper.ImageManager imgMng = new Library.FileHelper.ImageManager(FrameworkSetting.Setting.AbsoluteFileFolder, FrameworkSetting.Setting.AbsoluteThumbnailFolder); using (FrameworkEntities context = CreateContext()) { try { Files _file = context.Files.FirstOrDefault(o => o.FileUD == fileUD); if (_file != null) { if (!string.IsNullOrEmpty(_file.FileLocation)) { try { imgMng.DeleteFile(_file.FileLocation); } catch { } } if (!string.IsNullOrEmpty(_file.ThumbnailLocation)) { try { imgMng.DeleteFile(_file.ThumbnailLocation); } catch { } } context.Files.Remove(_file); context.SaveChanges(); } return(true); } catch { return(false); } } }
public string CreateNoneImageFilePointer(string tmpFolder, string newFile, string oldFilePointer) { string result = string.Empty; Library.FileHelper.ImageManager imgMng = new Library.FileHelper.ImageManager(FrameworkSetting.Setting.AbsoluteFileFolder, FrameworkSetting.Setting.AbsoluteThumbnailFolder); using (FrameworkEntities context = CreateContext()) { // delete phisycal files Files _file = context.Files.FirstOrDefault(o => o.FileUD == oldFilePointer); if (_file != null) { if (!string.IsNullOrEmpty(_file.FileLocation)) { try { imgMng.DeleteFile(_file.FileLocation); } catch { } _file.FileLocation = string.Empty; } if (!string.IsNullOrEmpty(_file.ThumbnailLocation)) { try { imgMng.DeleteFile(_file.ThumbnailLocation); } catch { } _file.ThumbnailLocation = string.Empty; } // remove the file pointer if new file is empty if (string.IsNullOrEmpty(newFile)) { // remove file registration in database context.Files.Remove(_file); context.SaveChanges(); result = string.Empty; } } if (!string.IsNullOrEmpty(newFile)) { // assign new file string outFileFullPath, outDBFileLocation; // copy the new file imgMng.StoreFile(tmpFolder + newFile, out outDBFileLocation, out outFileFullPath); if (File.Exists(outFileFullPath)) { FileInfo info = new FileInfo(outFileFullPath); // insert/update file registration in database try { if (_file == null) { _file = new Files(); _file.FileUD = System.Guid.NewGuid().ToString().ToLower().Replace("-", ""); context.Files.Add(_file); } _file.FriendlyName = newFile; _file.FileLocation = outDBFileLocation; _file.FileExtension = info.Extension; _file.FileSize = (int)info.Length; context.SaveChanges(); result = _file.FileUD; } catch { result = string.Empty; } } } } return(result); }