개정판 2fb63a42
issue #000
file 추가
Change-Id: I40cb9b15b901edaf1841e3945c08ba350de7c309
ID2.Manager/ID2.Manager.Controller/Controllers/AttFileController.cs | ||
---|---|---|
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 |
using ID2.Manager.Dapper.Repository; |
|
9 |
|
|
10 |
namespace ID2.Manager.Controller.Controllers |
|
11 |
{ |
|
12 |
public class AttFileController : BaseController |
|
13 |
{ |
|
14 |
public IEnumerable<AttFileInfo> GetFileList(string refID, string category) |
|
15 |
{ |
|
16 |
try |
|
17 |
{ |
|
18 |
using (AttFileRepository rep = new AttFileRepository(this._MSSQLCONNSTR)) |
|
19 |
{ |
|
20 |
return rep.GetAttFileList(refID, category); |
|
21 |
} |
|
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 |
using (AttFileRepository rep = new AttFileRepository(this._MSSQLCONNSTR)) |
|
34 |
{ |
|
35 |
return rep.GetAttFileInfo(refID, category); |
|
36 |
} |
|
37 |
} |
|
38 |
catch (Exception ex) |
|
39 |
{ |
|
40 |
throw ex; |
|
41 |
} |
|
42 |
} |
|
43 |
|
|
44 |
public bool SetAttFiles(List<AttFileInfo> attFiles, string userId) |
|
45 |
{ |
|
46 |
try |
|
47 |
{ |
|
48 |
using (AttFileRepository rep = new AttFileRepository(this._MSSQLCONNSTR)) |
|
49 |
{ |
|
50 |
return rep.SetAttFiles(attFiles, userId); |
|
51 |
} |
|
52 |
} |
|
53 |
catch (Exception ex) |
|
54 |
{ |
|
55 |
throw ex; |
|
56 |
} |
|
57 |
} |
|
58 |
} |
|
59 |
} |
ID2.Manager/ID2.Manager.Dapper/Repository/AttFileRepository.cs | ||
---|---|---|
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 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 |
query = $@" |
|
61 |
delete dbo.AttachFIles where RefID=@RefID and Category=@Category |
|
62 |
insert into dbo.AttachFIles (FileID,RefID,Category,FileType,FileName,FilePath,FileData,Creator) |
|
63 |
values |
|
64 |
( |
|
65 |
lower(newid()) |
|
66 |
,@RefID |
|
67 |
,@Category |
|
68 |
,@FileType |
|
69 |
,@FileName |
|
70 |
,@FilePath |
|
71 |
,@FileData |
|
72 |
,@Creator |
|
73 |
)"; |
|
74 |
break; |
|
75 |
default: |
|
76 |
query = $@" |
|
77 |
insert into dbo.AttachFIles (FileID,RefID,Category,FileType,FileName,FilePath,FileData,Creator) |
|
78 |
values |
|
79 |
( |
|
80 |
lower(newid()) |
|
81 |
,@RefID |
|
82 |
,@Category |
|
83 |
,@FileType |
|
84 |
,@FileName |
|
85 |
,@FilePath |
|
86 |
,@FileData |
|
87 |
,@Creator |
|
88 |
)"; |
|
89 |
break; |
|
90 |
} |
|
91 |
base.Execute(query, attFile, transaction); |
|
92 |
} |
|
93 |
|
|
94 |
transaction.Commit(); |
|
95 |
isSuccess = true; |
|
96 |
} |
|
97 |
} |
|
98 |
catch (Exception ex) |
|
99 |
{ |
|
100 |
throw ex; |
|
101 |
} |
|
102 |
|
|
103 |
return isSuccess; |
|
104 |
} |
|
105 |
} |
|
106 |
} |
ID2.Manager/ID2.Manager.Data/Models/AttFileInfo.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
|
|
7 |
using System.Runtime.Serialization; |
|
8 |
|
|
9 |
namespace ID2.Manager.Data.Models |
|
10 |
{ |
|
11 |
[DataContract] |
|
12 |
public class AttFileInfo |
|
13 |
{ |
|
14 |
[DataMember] |
|
15 |
public string FileID { get; set; } |
|
16 |
[DataMember] |
|
17 |
public string RefID { get; set; } |
|
18 |
[DataMember] |
|
19 |
public string Category { get; set; } |
|
20 |
[DataMember] |
|
21 |
public string FileType { get; set; } |
|
22 |
[DataMember] |
|
23 |
public string FileName { get; set; } |
|
24 |
[DataMember] |
|
25 |
public string FilePath { get; set; } |
|
26 |
[DataMember] |
|
27 |
public byte[] FileData { get; set; } |
|
28 |
[DataMember] |
|
29 |
public DateTime CreatedDate { get; set; } |
|
30 |
[DataMember] |
|
31 |
public string Creator { get; set; } |
|
32 |
} |
|
33 |
} |
내보내기 Unified diff