internal bool DeleteFile(int fileId) { bool result = false; try { using (FileStoreModel db = new FileStoreModel()) { PersonalFile pf = db.PersonalFiles.Find(fileId); if (pf != null) { pf.IsActive = false; db.Entry(pf).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } LogManager.LogTransaction("PersonalFile", AppVariables.UserId, fileId, TransactionTypes.Delete); result = true; } catch (Exception ex) { result = false; LogManager.LogException(ex, AppVariables.UserId, "FileManager", "DeleteFile"); } return(result); }
internal PersonalFile GetPersonalFileById(int fileId) { PersonalFile result = new PersonalFile(); try { using (FileStoreModel db = new FileStoreModel()) { result = (from p in db.PersonalFiles where p.IsActive == true && p.Id == fileId select p).FirstOrDefault <PersonalFile>(); } if (result == null) { result = new PersonalFile(); } if (result.FileContent == null) { result.FileContent = new byte[] { }; } } catch (Exception ex) { result = null; LogManager.LogException(ex, AppVariables.UserId, "FileManager", "GetPersonalFileById"); } return(result); }
public void AddNewFile(PersonalFile file, string userId) { var user = this._applicationUserServices.FindById(userId); using (var context = new SwuDBContext()) { context.Users.Attach(user); context.PersonalFiles.Add(file); context.SaveChanges(); } }
public bool RemoveFile(string id) { var ids = id.Split(','); foreach (var item in ids) { PersonalFile personalFile = _context.PersonalFiles.Find(int.Parse(item)); if (personalFile != null) { _context.PersonalFiles.Remove(personalFile); } } _context.SaveChanges(); return(true); }
internal bool AddFile(PersonalFile file) { bool result = false; try { using (FileStoreModel db = new FileStoreModel()) { db.PersonalFiles.Add(file); db.SaveChanges(); } LogManager.LogTransaction("PersonalFile", AppVariables.UserId, file.Id, TransactionTypes.Insert); result = true; } catch (Exception ex) { result = false; LogManager.LogException(ex, AppVariables.UserId, "FileManager", "AddFile"); } return(result); }
internal bool UpdateFile(PersonalFile file) { bool result = false; try { if (file != null) { using (FileStoreModel db = new FileStoreModel()) { PersonalFile pf = null; pf = db.PersonalFiles.Find(file.Id); if (pf != null) { pf.FileName = file.FileName; pf.FileContent = file.FileContent; db.Entry(pf).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); result = true; } } } if (result) { LogManager.LogTransaction("PersonalFile", AppVariables.UserId, file.Id, TransactionTypes.Update); } } catch (Exception ex) { result = false; LogManager.LogException(ex, AppVariables.UserId, "FileManager", "UpdateFile"); } return(result); }
public FrmFile(int fileId) { try { InitializeComponent(); _fileId = fileId; fileMan = new FileManager(); personFile = new PersonalFile(); isFileGet = false; this.Text = _fileId == -1 ? "Dosya Ekle" : "Dosya Güncelle"; if (_fileId > 0) { personFile = fileMan.GetPersonalFileById(_fileId); if (personFile != null) { lblFileName.Text = string.Format("Dosya : {0}", personFile.FileName); } } } catch (Exception ex) { LogManager.LogException(ex, AppVariables.UserId, "FrmFile", "Ctor"); } }
public AttachFilesProxy(PersonalFile f) { this.Id = f.Id; this.FilePath = f.FilePath; }
public static void UpdateFolderShareUser(string id, string shareUser) { PersonalFile.UpdateFolderShareUser(id, shareUser); }
public static int GetShareFolersCount(string ShareFolderIds) { return(PersonalFile.GetShareFolersCount(ShareFolderIds)); }
public static DataTable GetShareFolders(string ShareFolderIds, int pageSize, int pageIndex) { return(PersonalFile.GetShareFolders(ShareFolderIds, pageSize, pageIndex)); }
public static int GetAllFilesCount(string id, string startTime, string endTime, string fileName, double fileLowerSize, double fileHighSize, string userCode, bool isGetAll, bool isShare) { return(PersonalFile.GetAllFilesCount(id, startTime, endTime, fileName, fileLowerSize, fileHighSize, userCode, isGetAll, isShare)); }
public static DataTable GetAllFiles(string id, string startTime, string endTime, string fileName, double fileLowerSize, double fileHighSize, string userCode, bool isGetAll, bool isShare, int pageSize, int pageIndex) { return(PersonalFile.GetAllFiles(id, startTime, endTime, fileName, fileLowerSize, fileHighSize, userCode, isGetAll, isShare, pageSize, pageIndex)); }
public int Upload(UploadInput input) { var userId = HttpContext.Current.Session["UserID"].ToString(); var userName = HttpContext.Current.Session["UserName"].ToString(); UserDto userDto = new UserDto { UserID = userId, UserName = userName }; userService.SaveUser(userDto); PersonalFile personalFile = _context.PersonalFiles.FirstOrDefault(a => a.Id == input.Id); DocumentInfo documentInfo = null; CreateDocumentInput createDocumentInput = new CreateDocumentInput { CreateUserID = userId, CreateUserName = userName, FileName = input.FileName + "." + input.FileType, FileType = input.FileType }; //新建文件 if (input.CreateType == CreateType.newFile.ToString() && (personalFile == null || input.FileType != personalFile.FileType)) { MemoryStream stream = new MemoryStream(); if (input.FileType == FileType.xlsx.ToString()) { stream = new MemoryStream(NPOIHelper.CreateExcelFile()); } documentInfo = documentService.CreateDocument(createDocumentInput, stream); } else if (input.CreateType == CreateType.uploadFile.ToString() && (personalFile == null || HttpContext.Current.Request.Files.Count > 0)) { if (HttpContext.Current.Request.Files.Count == 0) { return(-1); } var uploadFile = HttpContext.Current.Request.Files[0]; createDocumentInput.FileName = uploadFile.FileName; createDocumentInput.FileType = createDocumentInput.FileName.Substring(createDocumentInput.FileName.LastIndexOf('.') + 1); input.FileName = createDocumentInput.FileName.Substring(0, createDocumentInput.FileName.LastIndexOf('.')); if (createDocumentInput.FileType == FileType.doc.ToString() || createDocumentInput.FileType == FileType.docx.ToString()) { input.FileType = FileType.docx.ToString(); } else { input.FileType = FileType.xlsx.ToString(); } documentInfo = documentService.CreateDocument(createDocumentInput, uploadFile.InputStream); } if (personalFile == null) { var createTime = DateTime.Now; personalFile = new PersonalFile { DocumentID = documentInfo.Id, CreateType = input.CreateType, FileName = input.FileName, FileType = input.FileType, CreateUserID = userId, CreateUserName = userName, CreateTime = createTime, ModifyUserID = userId, ModifyUserName = userName, ModifyTime = createTime }; _context.PersonalFiles.Add(personalFile); } else { //personalFile.CreateType = input.CreateType; personalFile.FileName = input.FileName; //personalFile.FileType = input.FileType; documentInfo = _context.DocumentInfos.FirstOrDefault(a => a.Id == personalFile.DocumentID); documentInfo.FileName = input.FileName + "." + personalFile.FileType; } _context.SaveChanges(); var shareUserList = JsonConvert.DeserializeObject <List <FileUserDto> >(input.ShareUserList); fileShareService.AddShareUser(new AddShareUserInput { FileId = personalFile.Id, FileUserDtos = shareUserList }); return(personalFile.Id); }