프로젝트

일반

사용자정보

통계
| 개정판:

hytos / ID2.Manager / ID2.Manager.Dapper / Repository / UserRepository.cs @ e8a86b9b

이력 | 보기 | 이력해설 | 다운로드 (2.32 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 82705273 yoush97
            try
18
            {
19
                string query = $@"select * from dbo.Users order by [Name]";
20 709c1971 yoush97
21 82705273 yoush97
                return Query<UserInfo>(query);
22
            }
23
            catch (Exception ex)
24
            {
25
                throw ex;
26
            }
27 709c1971 yoush97
        }
28
29 8164f84e yoush97
        public UserInfo GetUserInfo(string userId, string userPW)
30
        {
31 82705273 yoush97
            try
32
            {
33
                string query = $@"select * from dbo.Users where ID=@userId and Password=@userPW";
34 8164f84e yoush97
35 82705273 yoush97
                return Query<UserInfo>(query, new { userId, userPW }).FirstOrDefault();
36
            }
37
            catch (Exception ex)
38
            {
39
                throw ex;
40
            }
41 8164f84e yoush97
        }
42 91e72bfe yoush97
43 c52f8bbe yoush97
        public bool SetUserInfo(UserInfo userInfo, DMLType dmlType)
44 91e72bfe yoush97
        {
45
            bool isSuccess = false;
46
47
            try
48
            {
49
                using (var transaction = base.BeginTransaction())
50
                {
51
                    string query = string.Empty;
52
53 c52f8bbe yoush97
                    if (dmlType == DMLType.DELETE)
54 91e72bfe yoush97
                    {
55 c52f8bbe yoush97
                        query = $@"delete from dbo.Users where [UID]=@UID;";
56 91e72bfe yoush97
                    }
57
                    else
58
                    {
59 c52f8bbe yoush97
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 91e72bfe yoush97
update dbo.Users
70
set    Password=@Password
71 c52f8bbe yoush97
,Role=@Role
72 91e72bfe yoush97
where  [UID]=@UID;";
73 c52f8bbe yoush97
                        }
74 91e72bfe yoush97
                    }
75
76
                    Execute(query, userInfo, transaction);
77 c52f8bbe yoush97
78
                    transaction.Commit();
79
                    isSuccess = true;
80 91e72bfe yoush97
                }
81
            }
82
            catch (Exception ex)
83
            {
84
                throw ex;
85
            }
86
87
            return isSuccess;
88
        }
89 8164f84e yoush97
    }
90
}
클립보드 이미지 추가 (최대 크기: 500 MB)