hytos / ID2.Manager / ID2.Manager.Dapper / Repository / AttFileRepository.cs @ e8a86b9b
이력 | 보기 | 이력해설 | 다운로드 (2.55 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 | select top 1 * from dbo.AttachFIles where RefID=@RefID and Category=@Category order by CreatedDate"; |
||
35 | 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 | |||
57 | switch (attFile.Category) |
||
58 | { |
||
59 | case "notice": |
||
60 | 677a1d1f | yoush97 | query = $@"delete dbo.AttachFIles where RefID=@RefID and Category=@Category"; |
61 | 2fb63a42 | yoush97 | break; |
62 | 677a1d1f | yoush97 | } |
63 | query += $@" |
||
64 | insert into dbo.AttachFIles (FileID,RefID,Category,FileType,FileName,FilePath,FileExtension,FileData,Creator) |
||
65 | 2fb63a42 | yoush97 | values |
66 | ( |
||
67 | 677a1d1f | yoush97 | lower(newid()) |
68 | ,@RefID |
||
69 | ,@Category |
||
70 | ,@FileType |
||
71 | ,@FileName |
||
72 | ,@FilePath |
||
73 | ,@FileExtension |
||
74 | ,@FileData |
||
75 | ,@Creator |
||
76 | 2fb63a42 | yoush97 | )"; |
77 | 677a1d1f | yoush97 | |
78 | 2fb63a42 | yoush97 | base.Execute(query, attFile, transaction); |
79 | } |
||
80 | |||
81 | transaction.Commit(); |
||
82 | isSuccess = true; |
||
83 | } |
||
84 | } |
||
85 | catch (Exception ex) |
||
86 | { |
||
87 | throw ex; |
||
88 | } |
||
89 | |||
90 | return isSuccess; |
||
91 | } |
||
92 | } |
||
93 | } |