[6050] | 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 |
|
---|
[6117] | 13 |
|
---|
[6050] | 14 | public String SelectedSubMenu { get; set; }
|
---|
[6161] | 15 | public IList<AlgorithmClass> AlgorithmClassProp { get { return AlgorithmClassGetAll(); } set { ;} }
|
---|
[6050] | 16 |
|
---|
[6161] | 17 |
|
---|
[6117] | 18 | //***************************************Algorithm Class********************************************
|
---|
[6050] | 19 | //get all algorithm classes
|
---|
[6161] | 20 | private IList<AlgorithmClass> AlgorithmClassGetAll() {
|
---|
[6050] | 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
|
---|
[6117] | 35 |
|
---|
[6161] | 36 | private long AddAlgorithmClass(AlgorithmClass algorithmClass) {
|
---|
[6117] | 37 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
| 38 |
|
---|
| 39 | if (adminClient != null) {
|
---|
[6161] | 40 | return adminClient.AddAlgorithmClass(algorithmClass);
|
---|
[6117] | 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 |
|
---|
[6161] | 54 | public long SaveAlgorithmClass(AlgorithmClass algorithmClass) {
|
---|
[6117] | 55 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
| 56 |
|
---|
| 57 | if (adminClient != null) {
|
---|
[6161] | 58 | if (algorithmClass.Id == 0) {
|
---|
| 59 | return AddAlgorithmClass(algorithmClass);
|
---|
| 60 | }
|
---|
| 61 | else {
|
---|
| 62 | AlgorithmClass ac = adminClient.GetAlgorithmClass(algorithmClass.Id);
|
---|
[6117] | 63 |
|
---|
[6161] | 64 | if (ac != null) {
|
---|
| 65 | adminClient.UpdateAlgorithmClass(algorithmClass);
|
---|
| 66 | return algorithmClass.Id;
|
---|
| 67 | }
|
---|
[6117] | 68 | }
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[6161] | 71 | return 0;
|
---|
| 72 | }//SaveAlgorithmClass
|
---|
| 73 |
|
---|
[6117] | 74 | //***************************************Algorithms*************************************************
|
---|
[6050] | 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 |
|
---|
[6161] | 92 | private long AddAlgorithm(Algorithm algorithm) {
|
---|
[6117] | 93 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
| 94 |
|
---|
| 95 | if (adminClient != null) {
|
---|
[6161] | 96 | return adminClient.AddAlgorithm(algorithm);
|
---|
[6117] | 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 |
|
---|
[6161] | 110 | public long SaveAlgorithm(Algorithm algorithm) {
|
---|
[6117] | 111 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
| 112 |
|
---|
| 113 | if (adminClient != null) {
|
---|
[6161] | 114 | if (algorithm.Id == 0) {
|
---|
| 115 | return AddAlgorithm(algorithm);
|
---|
| 116 | }
|
---|
| 117 | else {
|
---|
| 118 | Algorithm al = adminClient.GetAlgorithm(algorithm.Id);
|
---|
[6117] | 119 |
|
---|
[6161] | 120 | if (al != null) {
|
---|
| 121 | adminClient.UpdateAlgorithm(algorithm);
|
---|
| 122 | return algorithm.Id;
|
---|
| 123 | }
|
---|
[6117] | 124 | }
|
---|
| 125 | }
|
---|
| 126 |
|
---|
[6161] | 127 | return 0;
|
---|
| 128 | }//SaveAlgorithm
|
---|
| 129 |
|
---|
[6117] | 130 | //***************************************Problem Class**********************************************
|
---|
[6050] | 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 |
|
---|
[6161] | 146 | private long AddProblemClass(ProblemClass problemClass) {
|
---|
[6117] | 147 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
| 148 |
|
---|
| 149 | if (adminClient != null) {
|
---|
[6161] | 150 | return adminClient.AddProblemClass(problemClass);
|
---|
[6117] | 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 |
|
---|
[6161] | 164 | public long SaveProblemClass(ProblemClass problemClass) {
|
---|
[6117] | 165 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
| 166 |
|
---|
| 167 | if (adminClient != null) {
|
---|
[6161] | 168 | if (problemClass.Id == 0) {
|
---|
| 169 | return AddProblemClass(problemClass);
|
---|
| 170 | }
|
---|
| 171 | else {
|
---|
| 172 | ProblemClass pc = adminClient.GetProblemClass(problemClass.Id);
|
---|
[6117] | 173 |
|
---|
[6161] | 174 | if (pc != null) {
|
---|
| 175 | adminClient.UpdateProblemClass(problemClass);
|
---|
| 176 | return problemClass.Id;
|
---|
| 177 | }
|
---|
[6117] | 178 | }
|
---|
| 179 | }
|
---|
| 180 |
|
---|
[6161] | 181 | return 0;
|
---|
| 182 | }//SaveProblemClass
|
---|
| 183 |
|
---|
[6117] | 184 | //***************************************Problems***************************************************
|
---|
[6050] | 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
|
---|
[6117] | 200 |
|
---|
[6161] | 201 | private long AddProblem(Problem problem) {
|
---|
[6117] | 202 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
| 203 |
|
---|
| 204 | if (adminClient != null) {
|
---|
[6161] | 205 | return adminClient.AddProblem(problem);
|
---|
[6117] | 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 |
|
---|
[6161] | 219 | public long SaveProblem(Problem problem) {
|
---|
[6117] | 220 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
| 221 |
|
---|
| 222 | if (adminClient != null) {
|
---|
[6161] | 223 | if (problem.Id == 0) {
|
---|
| 224 | return AddProblem(problem);
|
---|
| 225 | }
|
---|
| 226 | else {
|
---|
| 227 | Problem pr = adminClient.GetProblem(problem.Id);
|
---|
[6117] | 228 |
|
---|
[6161] | 229 | if (pr != null) {
|
---|
| 230 | adminClient.UpdateProblem(problem);
|
---|
| 231 | return problem.Id;
|
---|
| 232 | }
|
---|
| 233 | }
|
---|
[6117] | 234 | }
|
---|
[6161] | 235 |
|
---|
| 236 | return 0;
|
---|
| 237 | }//SaveProblem
|
---|
[6050] | 238 | }
|
---|
| 239 | } |
---|