1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Web;
|
---|
5 | using HLWebOKBAdminPlugin.OKBAdministrationService;
|
---|
6 | using HLWebOKBAdminPlugin.Helpers;
|
---|
7 |
|
---|
8 | namespace HLWebOKBAdminPlugin.Models {
|
---|
9 | public class AdminModel {
|
---|
10 | //member var
|
---|
11 | private IList<AlgorithmClass> algorithmClassList;
|
---|
12 |
|
---|
13 |
|
---|
14 | public String SelectedSubMenu { get; set; }
|
---|
15 | public IList<AlgorithmClass> AlgorithmClassProp { get { return AlgorithmClassGetAll(); } set { ;} }
|
---|
16 |
|
---|
17 |
|
---|
18 | //***************************************Algorithm Class********************************************
|
---|
19 | //get all algorithm classes
|
---|
20 | private IList<AlgorithmClass> AlgorithmClassGetAll() {
|
---|
21 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
22 |
|
---|
23 | algorithmClassList = new List<AlgorithmClass>();
|
---|
24 |
|
---|
25 | if (adminClient != null) {
|
---|
26 | AlgorithmClass[] algorithmClasses = adminClient.GetAlgorithmClasses();
|
---|
27 | foreach (AlgorithmClass ac in algorithmClasses) {
|
---|
28 | algorithmClassList.Add(ac);
|
---|
29 |
|
---|
30 | }
|
---|
31 | }//if (adminClient != null)
|
---|
32 |
|
---|
33 | return algorithmClassList;
|
---|
34 | }//AlgorithmClassGetAll
|
---|
35 |
|
---|
36 | private long AddAlgorithmClass(AlgorithmClass algorithmClass) {
|
---|
37 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
38 |
|
---|
39 | if (adminClient != null) {
|
---|
40 | return adminClient.AddAlgorithmClass(algorithmClass);
|
---|
41 | }
|
---|
42 |
|
---|
43 | return 0;
|
---|
44 | }//AddAlgorithmClass
|
---|
45 |
|
---|
46 | public void DeleteAlgorithmClass(long id) {
|
---|
47 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
48 |
|
---|
49 | if (adminClient != null){
|
---|
50 | adminClient.DeleteAlgorithmClass(id);
|
---|
51 | }
|
---|
52 | }//DeleteAlgorithmClass
|
---|
53 |
|
---|
54 | public long SaveAlgorithmClass(AlgorithmClass algorithmClass) {
|
---|
55 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
56 |
|
---|
57 | if (adminClient != null) {
|
---|
58 | if (algorithmClass.Id == 0) {
|
---|
59 | return AddAlgorithmClass(algorithmClass);
|
---|
60 | }
|
---|
61 | else {
|
---|
62 | AlgorithmClass ac = adminClient.GetAlgorithmClass(algorithmClass.Id);
|
---|
63 |
|
---|
64 | if (ac != null) {
|
---|
65 | adminClient.UpdateAlgorithmClass(algorithmClass);
|
---|
66 | return algorithmClass.Id;
|
---|
67 | }
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | return 0;
|
---|
72 | }//SaveAlgorithmClass
|
---|
73 |
|
---|
74 | //***************************************Algorithms*************************************************
|
---|
75 | //get all algorithms
|
---|
76 | public IList<Algorithm> AlgorithmsGetAll() {
|
---|
77 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
78 |
|
---|
79 | IList<Algorithm> algorithmList = new List<Algorithm>();
|
---|
80 |
|
---|
81 | if (adminClient != null) {
|
---|
82 | Algorithm[] algorithm = adminClient.GetAlgorithms();
|
---|
83 | foreach (Algorithm al in algorithm) {
|
---|
84 | algorithmList.Add(al);
|
---|
85 |
|
---|
86 | }
|
---|
87 | }//if (adminClient != null)
|
---|
88 |
|
---|
89 | return algorithmList;
|
---|
90 | }//AlgorithmsGetAll
|
---|
91 |
|
---|
92 | private long AddAlgorithm(Algorithm algorithm) {
|
---|
93 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
94 |
|
---|
95 | if (adminClient != null) {
|
---|
96 | return adminClient.AddAlgorithm(algorithm);
|
---|
97 | }
|
---|
98 |
|
---|
99 | return 0;
|
---|
100 | }//AddAlgorithm
|
---|
101 |
|
---|
102 | public void DeleteAlgorithm(long id) {
|
---|
103 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
104 |
|
---|
105 | if (adminClient != null) {
|
---|
106 | adminClient.DeleteAlgorithm(id);
|
---|
107 | }
|
---|
108 | }//DeleteAlgorithm
|
---|
109 |
|
---|
110 | public long SaveAlgorithm(Algorithm algorithm) {
|
---|
111 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
112 |
|
---|
113 | if (adminClient != null) {
|
---|
114 | if (algorithm.Id == 0) {
|
---|
115 | return AddAlgorithm(algorithm);
|
---|
116 | }
|
---|
117 | else {
|
---|
118 | Algorithm al = adminClient.GetAlgorithm(algorithm.Id);
|
---|
119 |
|
---|
120 | if (al != null) {
|
---|
121 | adminClient.UpdateAlgorithm(algorithm);
|
---|
122 | return algorithm.Id;
|
---|
123 | }
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | return 0;
|
---|
128 | }//SaveAlgorithm
|
---|
129 |
|
---|
130 | //***************************************Problem Class**********************************************
|
---|
131 | public IList<ProblemClass> ProblemClassGetAll() {
|
---|
132 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
133 |
|
---|
134 | IList<ProblemClass> problemClassList = new List<ProblemClass>();
|
---|
135 |
|
---|
136 | if (adminClient != null) {
|
---|
137 | ProblemClass[] problemClasses = adminClient.GetProblemClasses();
|
---|
138 | foreach (ProblemClass pc in problemClasses) {
|
---|
139 | problemClassList.Add(pc);
|
---|
140 | }
|
---|
141 | }//if (adminClient != null)
|
---|
142 |
|
---|
143 | return problemClassList;
|
---|
144 | }//ProblemClassGetAll
|
---|
145 |
|
---|
146 | private long AddProblemClass(ProblemClass problemClass) {
|
---|
147 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
148 |
|
---|
149 | if (adminClient != null) {
|
---|
150 | return adminClient.AddProblemClass(problemClass);
|
---|
151 | }
|
---|
152 |
|
---|
153 | return 0;
|
---|
154 | }//AddProblemClass
|
---|
155 |
|
---|
156 | public void DeleteProblemClass(long id) {
|
---|
157 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
158 |
|
---|
159 | if (adminClient != null) {
|
---|
160 | adminClient.DeleteProblemClass(id);
|
---|
161 | }
|
---|
162 | }//DeleteProblemClass
|
---|
163 |
|
---|
164 | public long SaveProblemClass(ProblemClass problemClass) {
|
---|
165 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
166 |
|
---|
167 | if (adminClient != null) {
|
---|
168 | if (problemClass.Id == 0) {
|
---|
169 | return AddProblemClass(problemClass);
|
---|
170 | }
|
---|
171 | else {
|
---|
172 | ProblemClass pc = adminClient.GetProblemClass(problemClass.Id);
|
---|
173 |
|
---|
174 | if (pc != null) {
|
---|
175 | adminClient.UpdateProblemClass(problemClass);
|
---|
176 | return problemClass.Id;
|
---|
177 | }
|
---|
178 | }
|
---|
179 | }
|
---|
180 |
|
---|
181 | return 0;
|
---|
182 | }//SaveProblemClass
|
---|
183 |
|
---|
184 | //***************************************Problems***************************************************
|
---|
185 | public IList<Problem> ProblemsGetAll() {
|
---|
186 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
187 |
|
---|
188 | IList<Problem> problemList = new List<Problem>();
|
---|
189 |
|
---|
190 | if (adminClient != null) {
|
---|
191 | Problem[] problem = adminClient.GetProblems();
|
---|
192 | foreach (Problem pr in problem) {
|
---|
193 | problemList.Add(pr);
|
---|
194 |
|
---|
195 | }
|
---|
196 | }//if (adminClient != null)
|
---|
197 |
|
---|
198 | return problemList;
|
---|
199 | }//ProblemsGetAll
|
---|
200 |
|
---|
201 | private long AddProblem(Problem problem) {
|
---|
202 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
203 |
|
---|
204 | if (adminClient != null) {
|
---|
205 | return adminClient.AddProblem(problem);
|
---|
206 | }
|
---|
207 |
|
---|
208 | return 0;
|
---|
209 | }//AddProblem
|
---|
210 |
|
---|
211 | public void DeleteProblem(long id) {
|
---|
212 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
213 |
|
---|
214 | if (adminClient != null) {
|
---|
215 | adminClient.DeleteProblem(id);
|
---|
216 | }
|
---|
217 | }//DeleteProblem
|
---|
218 |
|
---|
219 | public long SaveProblem(Problem problem) {
|
---|
220 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
221 |
|
---|
222 | if (adminClient != null) {
|
---|
223 | if (problem.Id == 0) {
|
---|
224 | return AddProblem(problem);
|
---|
225 | }
|
---|
226 | else {
|
---|
227 | Problem pr = adminClient.GetProblem(problem.Id);
|
---|
228 |
|
---|
229 | if (pr != null) {
|
---|
230 | adminClient.UpdateProblem(problem);
|
---|
231 | return problem.Id;
|
---|
232 | }
|
---|
233 | }
|
---|
234 | }
|
---|
235 |
|
---|
236 | return 0;
|
---|
237 | }//SaveProblem
|
---|
238 | }
|
---|
239 | } |
---|