@@ -40,7 +40,7 @@ public async Task CreateAsync(DataFile dataFile, Stream stream, CancellationToke
4040 string path = GetDataFilePath ( filename ) ;
4141 try
4242 {
43- using Stream fileStream = _fileSystem . OpenWrite ( path ) ;
43+ await using Stream fileStream = _fileSystem . OpenWrite ( path ) ;
4444 await stream . CopyToAsync ( fileStream , cancellationToken ) ;
4545 await Entities . InsertAsync ( dataFile with { Filename = filename } , cancellationToken ) ;
4646 }
@@ -67,10 +67,10 @@ public async Task<DataFile> UpdateAsync(string id, Stream stream, CancellationTo
6767 bool deleteFile = false ;
6868 try
6969 {
70- using ( Stream fileStream = _fileSystem . OpenWrite ( path ) )
70+ await using ( Stream fileStream = _fileSystem . OpenWrite ( path ) )
7171 await stream . CopyToAsync ( fileStream , cancellationToken ) ;
7272 await _dataAccessContext . WithTransactionAsync (
73- async ( ct ) =>
73+ async ct =>
7474 {
7575 DataFile ? originalDataFile = await Entities . UpdateAsync (
7676 id ,
@@ -79,21 +79,16 @@ await _dataAccessContext.WithTransactionAsync(
7979 cancellationToken : ct
8080 ) ;
8181 if ( originalDataFile is null )
82- {
8382 throw new EntityNotFoundException ( $ "Could not find the DataFile '{ id } '.") ;
84- }
85- else
86- {
87- await _deletedFiles . InsertAsync (
88- new DeletedFile { Filename = originalDataFile . Filename , DeletedAt = DateTime . UtcNow } ,
89- cancellationToken : ct
90- ) ;
91- }
83+
84+ await _deletedFiles . InsertAsync (
85+ new DeletedFile { Filename = originalDataFile . Filename , DeletedAt = DateTime . UtcNow } ,
86+ cancellationToken : ct
87+ ) ;
9288 await _mediator . Publish ( new DataFileUpdated { DataFileId = id , Filename = filename } , ct ) ;
9389 } ,
9490 cancellationToken : cancellationToken
9591 ) ;
96- return await GetAsync ( id , cancellationToken ) ;
9792 }
9893 catch
9994 {
@@ -105,12 +100,13 @@ await _deletedFiles.InsertAsync(
105100 if ( deleteFile )
106101 _fileSystem . DeleteFile ( path ) ;
107102 }
103+
104+ return await GetAsync ( id , cancellationToken ) ;
108105 }
109106
110- public override async Task DeleteAsync ( string id , CancellationToken cancellationToken = default )
111- {
107+ public override async Task DeleteAsync ( string id , CancellationToken cancellationToken = default ) =>
112108 await _dataAccessContext . WithTransactionAsync (
113- async ( ct ) =>
109+ async ct =>
114110 {
115111 DataFile ? dataFile = await Entities . DeleteAsync ( id , ct ) ;
116112 if ( dataFile is null )
@@ -124,10 +120,6 @@ await _deletedFiles.InsertAsync(
124120 } ,
125121 cancellationToken : cancellationToken
126122 ) ;
127- }
128123
129- private string GetDataFilePath ( string filename )
130- {
131- return Path . Combine ( _options . CurrentValue . FilesDirectory , filename ) ;
132- }
124+ private string GetDataFilePath ( string filename ) => Path . Combine ( _options . CurrentValue . FilesDirectory , filename ) ;
133125}
0 commit comments