프로젝트

일반

사용자정보

통계
| 개정판:

hytos / ID2.Manager / ID2.Manager.Dapper / Repository / UserRepository.cs @ 7066b8a9

이력 | 보기 | 이력해설 | 다운로드 (2.05 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
            string query = $@"select * from dbo.Users order by [Name]";
18

    
19
            return Query<UserInfo>(query);
20
        }
21

    
22
        public UserInfo GetUserInfo(string userId, string userPW)
23
        {
24
            string query = $@"select * from dbo.Users where ID=@userId and Password=@userPW";
25

    
26
            return Query<UserInfo>(query, new { userId, userPW }).FirstOrDefault();
27
        }
28

    
29
        public bool SetUserInfo(UserInfo userInfo, DMLType dmlType)
30
        {
31
            bool isSuccess = false;
32

    
33
            try
34
            {
35
                using (var transaction = base.BeginTransaction())
36
                {
37
                    string query = string.Empty;
38

    
39
                    if (dmlType == DMLType.DELETE)
40
                    {
41
                        query = $@"delete from dbo.Users where [UID]=@UID;";
42
                    }
43
                    else
44
                    {
45

    
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
update dbo.Users
56
set    Password=@Password
57
,Role=@Role
58
where  [UID]=@UID;";
59
                        }
60
                    }
61

    
62
                    Execute(query, userInfo, transaction);
63

    
64
                    transaction.Commit();
65
                    isSuccess = true;
66
                }
67
            }
68
            catch (Exception ex)
69
            {
70
                throw ex;
71
            }
72

    
73
            return isSuccess;
74
        }
75
    }
76
}
클립보드 이미지 추가 (최대 크기: 500 MB)