hytos / ID2.Manager / ID2.Manager.Dapper / Repository / UserRepository.cs @ 90369b9c
이력 | 보기 | 이력해설 | 다운로드 (2.32 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 UserRepository : BaseRepository |
12 |
{ |
13 |
public UserRepository(string connectionStr) : base(connectionStr) {} |
14 |
|
15 |
public IEnumerable<UserInfo> GetAllUserInfo() |
16 |
{ |
17 |
try |
18 |
{ |
19 |
string query = $@"select * from dbo.Users order by [Name]"; |
20 |
|
21 |
return Query<UserInfo>(query); |
22 |
} |
23 |
catch (Exception ex) |
24 |
{ |
25 |
throw ex; |
26 |
} |
27 |
} |
28 |
|
29 |
public UserInfo GetUserInfo(string userId, string userPW) |
30 |
{ |
31 |
try |
32 |
{ |
33 |
string query = $@"select * from dbo.Users where ID=@userId and Password=@userPW"; |
34 |
|
35 |
return Query<UserInfo>(query, new { userId, userPW }).FirstOrDefault(); |
36 |
} |
37 |
catch (Exception ex) |
38 |
{ |
39 |
throw ex; |
40 |
} |
41 |
} |
42 |
|
43 |
public bool SetUserInfo(UserInfo userInfo, DMLType dmlType) |
44 |
{ |
45 |
bool isSuccess = false; |
46 |
|
47 |
try |
48 |
{ |
49 |
using (var transaction = base.BeginTransaction()) |
50 |
{ |
51 |
string query = string.Empty; |
52 |
|
53 |
if (dmlType == DMLType.DELETE) |
54 |
{ |
55 |
query = $@"delete from dbo.Users where [UID]=@UID;"; |
56 |
} |
57 |
else |
58 |
{ |
59 |
|
60 |
if (userInfo.UID == null) |
61 |
{ |
62 |
query = $@" |
63 |
insert into dbo.Users([UID], ID, [Name], RefProjectID, [Password], [Role]) |
64 |
values (lower(newid()), @ID, @Name, @RefProjectID, @Password, @Role);"; |
65 |
} |
66 |
else |
67 |
{ |
68 |
query = $@" |
69 |
update dbo.Users |
70 |
set Password=@Password |
71 |
,Role=@Role |
72 |
where [UID]=@UID;"; |
73 |
} |
74 |
} |
75 |
|
76 |
Execute(query, userInfo, transaction); |
77 |
|
78 |
transaction.Commit(); |
79 |
isSuccess = true; |
80 |
} |
81 |
} |
82 |
catch (Exception ex) |
83 |
{ |
84 |
throw ex; |
85 |
} |
86 |
|
87 |
return isSuccess; |
88 |
} |
89 |
} |
90 |
} |