Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 6117 was 6117, checked in by wtollsch, 13 years ago

#1433 completed add, delete and update methods for AlgorithmClass, Algorithm, ProblemClass, Problem in AdminModel

File size: 8.7 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 algorithmClassList; } set { ;} }
16
17        //***************************************Algorithm Class********************************************
18        //get all algorithm classes
19        public IList<AlgorithmClass> AlgorithmClassGetAll() {
20            AdministrationServiceClient adminClient = Admin.GetClientFactory();
21
22            algorithmClassList = new List<AlgorithmClass>();
23
24            if (adminClient != null) {
25                AlgorithmClass[] algorithmClasses = adminClient.GetAlgorithmClasses();
26                foreach (AlgorithmClass ac in algorithmClasses) {
27                    algorithmClassList.Add(ac);
28
29                }
30            }//if (adminClient != null)
31
32            return algorithmClassList;
33        }//AlgorithmClassGetAll
34
35        public long AddAlgorithmClass(string name, string description) {
36            AdministrationServiceClient adminClient = Admin.GetClientFactory();
37
38            if (adminClient != null) {
39                AlgorithmClass ac = new AlgorithmClass();
40                ac.Description = description;
41                ac.Name = name;
42
43                return adminClient.AddAlgorithmClass(ac);
44            }
45
46            return 0;
47        }//AddAlgorithmClass
48
49        public void DeleteAlgorithmClass(long id) {
50            AdministrationServiceClient adminClient = Admin.GetClientFactory();
51
52            if (adminClient != null){
53                adminClient.DeleteAlgorithmClass(id);
54            }
55        }//DeleteAlgorithmClass
56
57        public void UpdateAlgorithmClass(long id, string name, string description) {
58            AdministrationServiceClient adminClient = Admin.GetClientFactory();
59
60            if (adminClient != null) {
61                AlgorithmClass ac = adminClient.GetAlgorithmClass(id);
62
63                if (ac != null) {
64                    ac.Id = id;
65                    ac.Name = name;
66                    ac.Description = description;
67
68                    adminClient.UpdateAlgorithmClass(ac);
69                }
70            }
71        }//UpdateAlgorithmClass
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        public long AddAlgorithm(string name, string description, string dataTypeName, string dataTypeTypeName) {
92            AdministrationServiceClient adminClient = Admin.GetClientFactory();
93
94            if (adminClient != null) {
95                Algorithm al = new Algorithm();
96                al.DataTypeName = dataTypeName;
97                al.DataTypeTypeName = dataTypeTypeName;
98                al.Description = description;
99                al.Name = name;
100
101                return adminClient.AddAlgorithm(al);
102            }
103
104            return 0;
105        }//AddAlgorithm
106
107        public void DeleteAlgorithm(long id) {
108            AdministrationServiceClient adminClient = Admin.GetClientFactory();
109
110            if (adminClient != null) {
111                adminClient.DeleteAlgorithm(id);
112            }
113        }//DeleteAlgorithm
114
115        public void UpdateAlgorithm(long id, string name, string description, string dataTypeName, string dataTypeTypeName) {
116            AdministrationServiceClient adminClient = Admin.GetClientFactory();
117
118            if (adminClient != null) {
119                Algorithm al = adminClient.GetAlgorithm(id);
120
121                if (al != null){
122                    al.DataTypeName = dataTypeName;
123                    al.DataTypeTypeName = dataTypeTypeName;
124                    al.Description = description;
125                    al.Name = name;
126
127                    adminClient.UpdateAlgorithm(al);
128                }
129            }
130        }//UpdateAlgorithm
131
132        //***************************************Problem Class**********************************************
133        public IList<ProblemClass> ProblemClassGetAll() {
134            AdministrationServiceClient adminClient = Admin.GetClientFactory();
135
136            IList<ProblemClass> problemClassList = new List<ProblemClass>();
137
138            if (adminClient != null) {
139                ProblemClass[] problemClasses = adminClient.GetProblemClasses();
140                foreach (ProblemClass pc in problemClasses) {
141                    problemClassList.Add(pc);
142                }
143            }//if (adminClient != null)
144
145            return problemClassList;
146        }//ProblemClassGetAll
147
148        public long AddProblemClass(string name, string description) {
149            AdministrationServiceClient adminClient = Admin.GetClientFactory();
150
151            if (adminClient != null) {
152                ProblemClass pc = new ProblemClass();
153                pc.Description = description;
154                pc.Name = name;
155
156                return adminClient.AddProblemClass(pc);
157            }
158
159            return 0;
160        }//AddProblemClass
161
162        public void DeleteProblemClass(long id) {
163            AdministrationServiceClient adminClient = Admin.GetClientFactory();
164
165            if (adminClient != null) {
166                adminClient.DeleteProblemClass(id);
167            }
168        }//DeleteProblemClass
169
170        public void UpdateProblemClass(long id, string name, string description) {
171            AdministrationServiceClient adminClient = Admin.GetClientFactory();
172
173            if (adminClient != null) {
174                ProblemClass pc = adminClient.GetProblemClass(id);
175               
176                if (pc != null){
177                    pc.Id = id;
178                    pc.Name = name;
179                    pc.Description = description;
180
181                    adminClient.UpdateProblemClass(pc);
182                }
183            }
184        }//UpdateProblemClass
185
186        //***************************************Problems***************************************************
187        public IList<Problem> ProblemsGetAll() {
188            AdministrationServiceClient adminClient = Admin.GetClientFactory();
189
190            IList<Problem> problemList = new List<Problem>();
191
192            if (adminClient != null) {
193                Problem[] problem = adminClient.GetProblems();
194                foreach (Problem pr in problem) {
195                    problemList.Add(pr);
196
197                }
198            }//if (adminClient != null)
199
200            return problemList;
201        }//ProblemsGetAll
202
203        public long AddProblem(string name, string description, string dataTypeName, string dataTypeTypeName) {
204            AdministrationServiceClient adminClient = Admin.GetClientFactory();
205
206            if (adminClient != null) {
207                Problem pr = new Problem();
208                pr.DataTypeName = dataTypeName;
209                pr.DataTypeTypeName = dataTypeTypeName;
210                pr.Description = description;
211                pr.Name = name;
212
213                return adminClient.AddProblem(pr);
214            }
215
216            return 0;
217        }//AddProblem
218
219        public void DeleteProblem(long id) {
220            AdministrationServiceClient adminClient = Admin.GetClientFactory();
221
222            if (adminClient != null) {
223                adminClient.DeleteProblem(id);
224            }
225        }//DeleteProblem
226
227        public void UpdateProblem(long id, string name, string description, string dataTypeName, string dataTypeTypeName) {
228            AdministrationServiceClient adminClient = Admin.GetClientFactory();
229
230            if (adminClient != null) {
231                Problem pr = adminClient.GetProblem(id);
232               
233                if (pr != null) {
234                    pr.DataTypeName = dataTypeName;
235                    pr.DataTypeTypeName = dataTypeTypeName;
236                    pr.Description = description;
237                    pr.Name = name;
238
239                    adminClient.UpdateProblem(pr);
240                }
241            }
242        }//UpdateProblem
243    }
244}
Note: See TracBrowser for help on using the repository browser.