프로젝트

일반

사용자정보

통계
| 개정판:

hytos / ID2.Manager / ID2.Manager.Dapper / Repository / ProjectRepository.cs @ 8d292359

이력 | 보기 | 이력해설 | 다운로드 (2.3 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 ProjectRepository : BaseRepository
12
    {
13
        public ProjectRepository(string connectionStr) : base(connectionStr) { }
14

    
15
        public IEnumerable<ProjectInfo> GetProjectGroupList()
16
        {
17
            string query = $@"
18
select   ProjectID
19
	    ,Code
20
		,[Name]
21
        ,isnull(Description,'') Description
22
        ,isnull(ID2Path,'') ID2Path
23
	    ,isnull(ParentID,'') GroupID
24
        ,convert(varchar(255),'') GroupName
25
		,1 [Level]
26
from     dbo.Projects
27
where    ParentID is null
28
order by [Name];";
29

    
30
            return Query<ProjectInfo>(query);
31
        }
32

    
33
        public IEnumerable<ProjectInfo> GetProjectList(string ProjectID, bool IsGroup)
34
        {
35
            string query = $@"
36
;with Prj as
37
(
38
    select ProjectID
39
	      ,Code
40
		  ,[Name]
41
          ,isnull(Description,'') Description
42
          ,isnull(ID2Path,'') ID2Path
43
	      ,isnull(ParentID,'') GroupID
44
          ,convert(varchar(255),'') GroupName
45
		  ,1 [Level]
46
	from   dbo.Projects
47
	where  ParentID is null and ProjectID=@ProjectID
48

    
49
	UNION ALL
50

    
51
	select p.ProjectID
52
	      ,p.Code
53
		  ,p.[Name]
54
	      ,p.Description
55
		  ,p.ID2Path
56
          ,p.ParentID GroupID
57
		  ,pp.[Name] GroupName
58
          ,pp.[Level]+1 [Level]
59
    FROM   dbo.Projects p
60
               inner join Prj pp ON p.ParentID=pp.ProjectID)";
61
            if (IsGroup)
62
            {
63
                query += $@"
64
select *
65
from   prj
66
order  by [Level], [Name];";
67
            }
68
            else
69
            {
70
                query += $@"
71
select *
72
from   prj
73
where  ProjectID <> @ProjectID
74
order  by [Level], [Name];";
75
            }
76

    
77
            return Query<ProjectInfo>(query, new { ProjectID });
78
        }
79

    
80
        public ProjectInfo GetProjectInfo(string ProjectID)
81
        {
82
            string query = $@"
83
select p.ProjectID
84
	    ,p.Code
85
		,p.[Name]
86
	    ,p.Description
87
        ,p.ID2Path
88
	    ,p.ParentID GroupID
89
        ,pp.[Name] GroupName
90
		,2 [Level]
91
from   dbo.Projects p
92
           inner join dbo.Projects pp on p.ParentID=pp.ProjectID
93
where  p.ParentID is not null
94
   and p.ProjectID=@ProjectID;";
95

    
96
            return Query<ProjectInfo>(query, new { ProjectID }).FirstOrDefault();
97
        }
98
    }
99
}