hytos / ID2.Manager / ID2.Manager.Dapper / Repository / AttFileRepository.cs @ 4142eefa
이력 | 보기 | 이력해설 | 다운로드 (2.26 KB)
1 | 2fb63a42 | yoush97 | 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 AttFileRepository : BaseRepository |
||
12 | { |
||
13 | public AttFileRepository(string connectionStr) : base(connectionStr) { } |
||
14 | |||
15 | public IEnumerable<AttFileInfo> GetAttFileList(string refID, string category) |
||
16 | { |
||
17 | try |
||
18 | { |
||
19 | string query = $@" |
||
20 | select * from dbo.AttachFIles where RefID=@RefID and Category=@Category order by CreatedDate"; |
||
21 | return Query<AttFileInfo>(query, new { RefID = refID, Category = category }); |
||
22 | } |
||
23 | catch (Exception ex) |
||
24 | { |
||
25 | throw ex; |
||
26 | } |
||
27 | } |
||
28 | |||
29 | public AttFileInfo GetAttFileInfo(string refID, string category) |
||
30 | { |
||
31 | try |
||
32 | { |
||
33 | string query = $@" |
||
34 | 4142eefa | yoush97 | select top 1 * from dbo.AttachFIles where RefID=@RefID and Category=@Category order by CreatedDate desc"; |
35 | 2fb63a42 | yoush97 | return QueryFirstOrDefault<AttFileInfo>(query, new { RefID = refID, Category = category }); |
36 | } |
||
37 | catch (Exception ex) |
||
38 | { |
||
39 | throw ex; |
||
40 | } |
||
41 | } |
||
42 | |||
43 | public bool SetAttFiles(List<AttFileInfo> attFiles, string userId) |
||
44 | { |
||
45 | bool isSuccess = false; |
||
46 | |||
47 | try |
||
48 | { |
||
49 | string query = string.Empty; |
||
50 | |||
51 | using (var transaction = base.BeginTransaction()) |
||
52 | { |
||
53 | foreach (AttFileInfo attFile in attFiles) |
||
54 | { |
||
55 | attFile.Creator = userId; |
||
56 | 4142eefa | yoush97 | query = $@" |
57 | 677a1d1f | yoush97 | insert into dbo.AttachFIles (FileID,RefID,Category,FileType,FileName,FilePath,FileExtension,FileData,Creator) |
58 | 2fb63a42 | yoush97 | values |
59 | ( |
||
60 | 677a1d1f | yoush97 | lower(newid()) |
61 | ,@RefID |
||
62 | ,@Category |
||
63 | ,@FileType |
||
64 | ,@FileName |
||
65 | ,@FilePath |
||
66 | ,@FileExtension |
||
67 | ,@FileData |
||
68 | ,@Creator |
||
69 | 2fb63a42 | yoush97 | )"; |
70 | base.Execute(query, attFile, transaction); |
||
71 | } |
||
72 | |||
73 | transaction.Commit(); |
||
74 | isSuccess = true; |
||
75 | } |
||
76 | } |
||
77 | catch (Exception ex) |
||
78 | { |
||
79 | throw ex; |
||
80 | } |
||
81 | |||
82 | return isSuccess; |
||
83 | } |
||
84 | } |
||
85 | } |