public BasicResponse RemoveFile(int id) { using (var tran = _dataContext.Database.BeginTransaction()) { try { var fileInfo = _dataContext.FileStreamInfo.Where(x => x.FileId == id).FirstOrDefault(); if (fileInfo != null) { var fileData = _dataContext.FileStreamData.Where(x => x.FileId == fileInfo.FileId).FirstOrDefault(); var deleteFileInfo = _dataContext.FileStreamInfo.Remove(fileInfo); var deleteFileData = _dataContext.FileStreamData.Remove(fileData); _dataContext.SaveChanges(); tran.Commit(); tran.Dispose(); return(BasicResponse.Succeed("Remove file successfully")); } tran.Dispose(); return(BasicResponse.Failed("Remove file fail")); } catch { tran.Rollback(); tran.Dispose(); throw; } } }
public int RestoreFileInfo(int fileId) { try { var fileInfo = _dataContext.FileStreamInfo.Where(x => x.FileId == fileId && x.Deleted == true).SingleOrDefault(); if (fileInfo != null) { fileInfo.Deleted = false; _dataContext.FileStreamInfo.Update(fileInfo); return(_dataContext.SaveChanges()); } return(0); } catch { throw; } }
public bool DeleteFile(int id) { using (var tran = _dataContext.Database.BeginTransaction()) { try { var fileInfo = _dataContext.FileStreamInfo.Where(x => x.FileId == id).FirstOrDefault(); var fileData = _dataContext.FileStreamData.Where(x => x.FileId == fileInfo.FileId).FirstOrDefault(); var deleteFileInfo = _dataContext.FileStreamInfo.Remove(fileInfo); var deleteFileData = _dataContext.FileStreamData.Remove(fileData); _dataContext.SaveChanges(); tran.Commit(); tran.Dispose(); return(true); } catch { tran.Rollback(); tran.Dispose(); throw; } } }