개정판 a23d0a0c
issue #000
프로젝트셍업 수정
Change-Id: Ib85afb675a90c8bb490512837500dd7407e9debb
ID2.Manager/ID2.Manager.Dapper/Repository/ProjectRepository.cs | ||
---|---|---|
116 | 116 |
public ProjectInfo GetProjectInfo(string ProjectID) |
117 | 117 |
{ |
118 | 118 |
string query = $@" |
119 |
select p.ProjectID |
|
120 |
,p.Code |
|
121 |
,p.[Name] |
|
122 |
,p.Description |
|
123 |
,p.ID2Path |
|
124 |
,p.ParentID GroupID |
|
125 |
,pp.[Name] GroupName |
|
126 |
,2 [Level] |
|
127 |
from dbo.Projects p |
|
128 |
inner join dbo.Projects pp on p.ParentID=pp.ProjectID |
|
129 |
where p.ParentID is not null |
|
130 |
and p.ProjectID=@ProjectID;"; |
|
119 |
;with Prj as |
|
120 |
( |
|
121 |
select ProjectID |
|
122 |
,Code |
|
123 |
,[Name] |
|
124 |
,isnull(Description,'') Description |
|
125 |
,isnull(ID2Path,'') ID2Path |
|
126 |
,isnull(ParentID,'') GroupID |
|
127 |
,convert(varchar(255),'') GroupName |
|
128 |
,1 [Level] |
|
129 |
from dbo.Projects |
|
130 |
where ParentID is null |
|
131 |
|
|
132 |
UNION ALL |
|
133 |
|
|
134 |
select p.ProjectID |
|
135 |
,p.Code |
|
136 |
,p.[Name] |
|
137 |
,p.Description |
|
138 |
,p.ID2Path |
|
139 |
,p.ParentID GroupID |
|
140 |
,pp.[Name] GroupName |
|
141 |
,pp.[Level]+1 [Level] |
|
142 |
FROM dbo.Projects p |
|
143 |
inner join Prj pp ON p.ParentID=pp.ProjectID |
|
144 |
) |
|
145 |
select * |
|
146 |
from prj |
|
147 |
where ProjectID=@ProjectID"; |
|
131 | 148 |
|
132 | 149 |
return Query<ProjectInfo>(query, new { ProjectID }).FirstOrDefault(); |
133 | 150 |
} |
151 |
|
|
152 |
public bool SetProjectData(ProjectInfo projectInfo, List<ID2ProjectInfo> id2ProjectList) |
|
153 |
{ |
|
154 |
bool isSuccess = false; |
|
155 |
|
|
156 |
try |
|
157 |
{ |
|
158 |
using (var transaction = base.BeginTransaction()) |
|
159 |
{ |
|
160 |
string query = string.Empty; |
|
161 |
|
|
162 |
if (projectInfo.ProjectID == null) |
|
163 |
{ |
|
164 |
query = $@" |
|
165 |
declare @newproject_uid table(projectId varchar(36)) |
|
166 |
insert into dbo.Projects(ProjectID, Code, [Name], [Description]) |
|
167 |
output inserted.ProjectID into @newproject_uid |
|
168 |
values (lower(newid()), @Code, @Name, @Description) |
|
169 |
if @@rowcount > 0 |
|
170 |
begin |
|
171 |
select projectId from @newproject_uid |
|
172 |
end |
|
173 |
else |
|
174 |
begin |
|
175 |
select '' projectId |
|
176 |
end;"; |
|
177 |
|
|
178 |
projectInfo.ProjectID = base.ExecuteScalar<string>(query, projectInfo, transaction); |
|
179 |
} |
|
180 |
else |
|
181 |
{ |
|
182 |
query = $@" |
|
183 |
update dbo.Projects |
|
184 |
set Code=@Code |
|
185 |
,[Name]=@Name |
|
186 |
,[Description]=@Description |
|
187 |
where ProjectID=@ProjectID;"; |
|
188 |
base.Execute(query, projectInfo, transaction); |
|
189 |
} |
|
190 |
|
|
191 |
if (id2ProjectList.Count > 0) |
|
192 |
{ |
|
193 |
var parameters = new Dictionary<string, object> |
|
194 |
{ |
|
195 |
{ "ParentID", projectInfo.ProjectID } |
|
196 |
}; |
|
197 |
|
|
198 |
string id2NameList = string.Join("','", id2ProjectList.Select(x => x.Name).ToList()); |
|
199 |
|
|
200 |
if (id2NameList.Length > 0) |
|
201 |
{ |
|
202 |
query = $@"delete dbo.Projects where ParentID=@ParentID and [Code] not in ('{id2NameList}');"; |
|
203 |
base.Execute(query, parameters, transaction); |
|
204 |
} |
|
205 |
} |
|
206 |
|
|
207 |
foreach (ID2ProjectInfo prj in id2ProjectList) |
|
208 |
{ |
|
209 |
if (!string.IsNullOrEmpty(prj.Name)) |
|
210 |
{ |
|
211 |
var parameters = new Dictionary<string, object> |
|
212 |
{ |
|
213 |
{ "ParentID", projectInfo.ProjectID }, |
|
214 |
{ "Name", prj.Name }, |
|
215 |
{ "Desc", prj.Desc }, |
|
216 |
{ "Path", prj.Path } |
|
217 |
}; |
|
218 |
|
|
219 |
query = $@" |
|
220 |
if exists(select * from dbo.Projects where ParentID=@ParentID and Code=@Name) |
|
221 |
begin |
|
222 |
update dbo.Projects |
|
223 |
set [Description]=@Desc |
|
224 |
,ID2Path=@Path |
|
225 |
where ParentID=@ParentID and Code=@Name |
|
226 |
end |
|
227 |
else |
|
228 |
begin |
|
229 |
insert into dbo.Projects |
|
230 |
( |
|
231 |
ProjectID |
|
232 |
,ParentID |
|
233 |
,Code |
|
234 |
,[Name] |
|
235 |
,[Description] |
|
236 |
,ID2Path |
|
237 |
) |
|
238 |
values |
|
239 |
( |
|
240 |
lower(newid()) |
|
241 |
,@ParentID |
|
242 |
,@Name |
|
243 |
,@Name |
|
244 |
,@Desc |
|
245 |
,@Path |
|
246 |
) |
|
247 |
end;"; |
|
248 |
base.Execute(query, parameters, transaction); |
|
249 |
} |
|
250 |
} |
|
251 |
|
|
252 |
transaction.Commit(); |
|
253 |
isSuccess = true; |
|
254 |
} |
|
255 |
} |
|
256 |
catch (Exception ex) |
|
257 |
{ |
|
258 |
throw ex; |
|
259 |
} |
|
260 |
|
|
261 |
return isSuccess; |
|
262 |
} |
|
263 |
|
|
264 |
public bool SetProjectGroupData(ProjectInfo projectInfo) |
|
265 |
{ |
|
266 |
bool isSuccess = false; |
|
267 |
|
|
268 |
try |
|
269 |
{ |
|
270 |
using (var transaction = base.BeginTransaction()) |
|
271 |
{ |
|
272 |
string query = string.Empty; |
|
273 |
|
|
274 |
query = $@" |
|
275 |
delete dbo.Projects where ParentID=@ProjectID; |
|
276 |
delete dbo.Projects where ProjectID=@ProjectID;"; |
|
277 |
|
|
278 |
base.Execute(query, projectInfo, transaction); |
|
279 |
|
|
280 |
transaction.Commit(); |
|
281 |
isSuccess = true; |
|
282 |
} |
|
283 |
} |
|
284 |
catch (Exception ex) |
|
285 |
{ |
|
286 |
throw ex; |
|
287 |
} |
|
288 |
|
|
289 |
return isSuccess; |
|
290 |
} |
|
134 | 291 |
} |
135 | 292 |
} |
내보내기 Unified diff