hytos / ID2.Manager / ID2.Manager.Dapper / Repository / FileRepository.cs @ fdecb3be
이력 | 보기 | 이력해설 | 다운로드 (1.41 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.Threading.Tasks; |
6 |
|
7 |
using ID2.Manager.Data.Models; |
8 |
|
9 |
namespace ID2.Manager.Dapper.Repository |
10 |
{ |
11 |
public class FileRepository : BaseRepository |
12 |
{ |
13 |
public FileRepository(string connectionStr) : base(connectionStr) { } |
14 |
|
15 |
public IEnumerable<FileInfo> GetFileList(string documentID) |
16 |
{ |
17 |
string query = $@" |
18 |
select * from dbo.Files where RefDocID=@documentID order by CreatedDate"; |
19 |
|
20 |
return Query<FileInfo>(query, new { documentID }); |
21 |
} |
22 |
|
23 |
public bool SetFileInfo(List<FileInfo> fileList) |
24 |
{ |
25 |
bool isSuccess = false; |
26 |
|
27 |
try |
28 |
{ |
29 |
using (var transaction = base.BeginTransaction()) |
30 |
{ |
31 |
foreach (FileInfo file in fileList) |
32 |
{ |
33 |
string query = $@" |
34 |
insert into dbo.Files (FileID, RefDocID, FileType, FileName, FilePath, FileData) |
35 |
values |
36 |
( |
37 |
lower(newid()) |
38 |
,@RefDocID |
39 |
,@FileType |
40 |
,@FileName |
41 |
,@FilePath |
42 |
,@FileData |
43 |
)"; |
44 |
base.Execute(query, file, transaction); |
45 |
} |
46 |
|
47 |
transaction.Commit(); |
48 |
isSuccess = true; |
49 |
} |
50 |
} |
51 |
catch (Exception ex) |
52 |
{ |
53 |
throw ex; |
54 |
} |
55 |
|
56 |
return isSuccess; |
57 |
} |
58 |
} |
59 |
} |