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