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