private protected void InsertFile(FileDto file, out Action revertCallback) { if (file is null) { throw new ArgumentNullException(nameof(file)); } Base.EnsureCachePersistence(typeof(NoteDoc)); var noteDocCache = Base.Caches[typeof(NoteDoc)]; var noteDoc = (NoteDoc)noteDocCache.CreateInstance(); noteDoc.NoteID = file.EntityNoteId; noteDoc.FileID = file.FileId; noteDocCache.Insert(noteDoc); Base.EnsureCachePersistence(typeof(UploadFile)); var uploadFileCache = Base.Caches[typeof(UploadFile)]; var uploadFile = (UploadFile)uploadFileCache.CreateInstance(); uploadFile.FileID = file.FileId; uploadFile.LastRevisionID = 1; uploadFile.Versioned = true; uploadFile.IsPublic = false; uploadFile.Name = file.FullName; uploadFile.PrimaryScreenID = PrimaryScreenID; uploadFileCache.Insert(uploadFile); Base.EnsureCachePersistence(typeof(UploadFileRevision)); var fileRevisionCache = Base.Caches[typeof(UploadFileRevision)]; var fileRevision = (UploadFileRevision)fileRevisionCache.CreateInstance(); fileRevision.FileID = file.FileId; fileRevision.FileRevisionID = 1; fileRevision.Data = file.Content; fileRevision.Size = UploadFileHelper.BytesToKilobytes(file.Content.Length); fileRevisionCache.Insert(fileRevision); revertCallback = () => { noteDocCache.SetStatus(noteDoc, PXEntryStatus.InsertedDeleted); uploadFileCache.SetStatus(uploadFile, PXEntryStatus.InsertedDeleted); fileRevisionCache.SetStatus(fileRevision, PXEntryStatus.InsertedDeleted); }; }
private void CreateFile(PXGraph graph, Guid noteId, Guid newFileId, string name, byte[] content) { var noteDocCache = graph.Caches[typeof(NoteDoc)]; var noteDoc = (NoteDoc)noteDocCache.CreateInstance(); noteDoc.NoteID = noteId; noteDoc.FileID = newFileId; noteDocCache.Insert(noteDoc); graph.EnsureCachePersistence(typeof(NoteDoc)); var uploadFileCache = graph.Caches[typeof(CommonMailReceiveProvider.UploadFile)]; var uploadFile = (CommonMailReceiveProvider.UploadFile)uploadFileCache.CreateInstance(); uploadFile.FileID = newFileId; uploadFile.LastRevisionID = 1; uploadFile.Versioned = true; uploadFile.IsPublic = false; if (name.Length > 200) { name = name.Substring(0, 200); } uploadFile.Name = newFileId + @"\" + name; uploadFile.PrimaryScreenID = "CR306015"; //TODO: need review uploadFileCache.Insert(uploadFile); graph.EnsureCachePersistence(typeof(CommonMailReceiveProvider.UploadFile)); var fileRevisionCache = graph.Caches[typeof(UploadFileRevision)]; var fileRevision = (UploadFileRevision)fileRevisionCache.CreateInstance(); fileRevision.FileID = newFileId; fileRevision.FileRevisionID = 1; fileRevision.Data = content; fileRevision.Size = UploadFileHelper.BytesToKilobytes(content.Length); fileRevisionCache.Insert(fileRevision); graph.EnsureCachePersistence(typeof(UploadFileRevision)); }