Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Models/AdminModel.cs @ 7605

Last change on this file since 7605 was 6317, checked in by jwolfing, 14 years ago

#1433 code formatted

File size: 7.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using HLWebOKBAdminPlugin.OKBAdministrationService;
6using HLWebOKBAdminPlugin.Helpers;
7
8namespace 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        } else {
61          AlgorithmClass ac = adminClient.GetAlgorithmClass(algorithmClass.Id);
62
63          if (ac != null) {
64            adminClient.UpdateAlgorithmClass(algorithmClass);
65            return algorithmClass.Id;
66          }
67        }
68      }
69
70      return 0;
71    }//SaveAlgorithmClass       
72
73    //***************************************Algorithms*************************************************
74    //get all algorithms
75    public IList<Algorithm> AlgorithmsGetAll() {
76      AdministrationServiceClient adminClient = Admin.GetClientFactory();
77
78      IList<Algorithm> algorithmList = new List<Algorithm>();
79
80      if (adminClient != null) {
81        Algorithm[] algorithm = adminClient.GetAlgorithms();
82        foreach (Algorithm al in algorithm) {
83          algorithmList.Add(al);
84
85        }
86      }//if (adminClient != null)
87
88      return algorithmList;
89    }//AlgorithmsGetAll
90
91    private long AddAlgorithm(Algorithm algorithm) {
92      AdministrationServiceClient adminClient = Admin.GetClientFactory();
93
94      if (adminClient != null) {
95        return adminClient.AddAlgorithm(algorithm);
96      }
97
98      return 0;
99    }//AddAlgorithm
100
101    public void DeleteAlgorithm(long id) {
102      AdministrationServiceClient adminClient = Admin.GetClientFactory();
103
104      if (adminClient != null) {
105        adminClient.DeleteAlgorithm(id);
106      }
107    }//DeleteAlgorithm
108
109    public long SaveAlgorithm(Algorithm algorithm) {
110      AdministrationServiceClient adminClient = Admin.GetClientFactory();
111
112      if (adminClient != null) {
113        if (algorithm.Id == 0) {
114          return AddAlgorithm(algorithm);
115        } else {
116          Algorithm al = adminClient.GetAlgorithm(algorithm.Id);
117
118          if (al != null) {
119            adminClient.UpdateAlgorithm(algorithm);
120            return algorithm.Id;
121          }
122        }
123      }
124
125      return 0;
126    }//SaveAlgorithm
127
128    //***************************************Problem Class**********************************************
129    public IList<ProblemClass> ProblemClassGetAll() {
130      AdministrationServiceClient adminClient = Admin.GetClientFactory();
131
132      IList<ProblemClass> problemClassList = new List<ProblemClass>();
133
134      if (adminClient != null) {
135        ProblemClass[] problemClasses = adminClient.GetProblemClasses();
136        foreach (ProblemClass pc in problemClasses) {
137          problemClassList.Add(pc);
138        }
139      }//if (adminClient != null)
140
141      return problemClassList;
142    }//ProblemClassGetAll
143
144    private long AddProblemClass(ProblemClass problemClass) {
145      AdministrationServiceClient adminClient = Admin.GetClientFactory();
146
147      if (adminClient != null) {
148        return adminClient.AddProblemClass(problemClass);
149      }
150
151      return 0;
152    }//AddProblemClass
153
154    public void DeleteProblemClass(long id) {
155      AdministrationServiceClient adminClient = Admin.GetClientFactory();
156
157      if (adminClient != null) {
158        adminClient.DeleteProblemClass(id);
159      }
160    }//DeleteProblemClass
161
162    public long SaveProblemClass(ProblemClass problemClass) {
163      AdministrationServiceClient adminClient = Admin.GetClientFactory();
164
165      if (adminClient != null) {
166        if (problemClass.Id == 0) {
167          return AddProblemClass(problemClass);
168        } else {
169          ProblemClass pc = adminClient.GetProblemClass(problemClass.Id);
170
171          if (pc != null) {
172            adminClient.UpdateProblemClass(problemClass);
173            return problemClass.Id;
174          }
175        }
176      }
177
178      return 0;
179    }//SaveProblemClass
180
181    //***************************************Problems***************************************************
182    public IList<Problem> ProblemsGetAll() {
183      AdministrationServiceClient adminClient = Admin.GetClientFactory();
184
185      IList<Problem> problemList = new List<Problem>();
186
187      if (adminClient != null) {
188        Problem[] problem = adminClient.GetProblems();
189        foreach (Problem pr in problem) {
190          problemList.Add(pr);
191
192        }
193      }//if (adminClient != null)
194
195      return problemList;
196    }//ProblemsGetAll
197
198    private long AddProblem(Problem problem) {
199      AdministrationServiceClient adminClient = Admin.GetClientFactory();
200
201      if (adminClient != null) {
202        return adminClient.AddProblem(problem);
203      }
204
205      return 0;
206    }//AddProblem
207
208    public void DeleteProblem(long id) {
209      AdministrationServiceClient adminClient = Admin.GetClientFactory();
210
211      if (adminClient != null) {
212        adminClient.DeleteProblem(id);
213      }
214    }//DeleteProblem
215
216    public long SaveProblem(Problem problem) {
217      AdministrationServiceClient adminClient = Admin.GetClientFactory();
218
219      if (adminClient != null) {
220        if (problem.Id == 0) {
221          return AddProblem(problem);
222        } else {
223          Problem pr = adminClient.GetProblem(problem.Id);
224
225          if (pr != null) {
226            adminClient.UpdateProblem(problem);
227            return problem.Id;
228          }
229        }
230      }
231
232      return 0;
233    }//SaveProblem
234
235
236  }
237}
Note: See TracBrowser for help on using the repository browser.