[6130] | 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 | {
|
---|
[6160] | 10 | public class ProblemModel {
|
---|
[6130] | 11 |
|
---|
[6160] | 12 | public String SelectedSubMenu { get; set; }
|
---|
| 13 | public IList<Problem> Problems { get { return ProblemsGetAll(); } set { ;} }
|
---|
| 14 | public IList<ProblemClass> ProblemClasses { get { return ProblemClassGetAll(); } }
|
---|
| 15 | public IList<Platform> Platforms { get { return PlatformsGetAll(); } }
|
---|
| 16 |
|
---|
| 17 | public Problem Problem { get; set; }
|
---|
| 18 |
|
---|
| 19 | public ProblemModel() {
|
---|
| 20 | Problem = new Problem();
|
---|
| 21 | }//ProblemModel
|
---|
| 22 |
|
---|
| 23 | //***************************************Problems***************************************************
|
---|
| 24 | private IList<Platform> PlatformsGetAll() {
|
---|
| 25 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
| 26 |
|
---|
| 27 | IList<Platform> platformList = new List<Platform>();
|
---|
| 28 |
|
---|
| 29 | if (adminClient != null) {
|
---|
| 30 | Platform[] platforms = adminClient.GetPlatforms();
|
---|
| 31 | foreach (Platform pl in platforms) {
|
---|
| 32 | platformList.Add(pl);
|
---|
| 33 | }
|
---|
| 34 | }//if (adminClient != null)
|
---|
| 35 |
|
---|
| 36 | return platformList;
|
---|
| 37 | }//ProblemClassGetAll
|
---|
| 38 |
|
---|
| 39 | private IList<ProblemClass> ProblemClassGetAll() {
|
---|
| 40 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
| 41 |
|
---|
| 42 | IList<ProblemClass> problemClassList = new List<ProblemClass>();
|
---|
| 43 |
|
---|
| 44 | if (adminClient != null) {
|
---|
| 45 | ProblemClass[] problemClasses = adminClient.GetProblemClasses();
|
---|
| 46 | foreach (ProblemClass pc in problemClasses) {
|
---|
| 47 | problemClassList.Add(pc);
|
---|
| 48 | }
|
---|
| 49 | }//if (adminClient != null)
|
---|
| 50 |
|
---|
| 51 | return problemClassList;
|
---|
| 52 | }//ProblemClassGetAll
|
---|
| 53 |
|
---|
| 54 | private IList<Problem> ProblemsGetAll() {
|
---|
| 55 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
| 56 |
|
---|
| 57 | IList<Problem> problemList = new List<Problem>();
|
---|
| 58 |
|
---|
| 59 | if (adminClient != null) {
|
---|
| 60 | Problem[] problem = adminClient.GetProblems();
|
---|
| 61 | foreach (Problem pr in problem) {
|
---|
| 62 | problemList.Add(pr);
|
---|
| 63 |
|
---|
| 64 | }
|
---|
| 65 | }//if (adminClient != null)
|
---|
| 66 |
|
---|
| 67 | return problemList;
|
---|
| 68 | }//ProblemsGetAll
|
---|
| 69 |
|
---|
| 70 | private long AddProblem(Problem problem) {
|
---|
| 71 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
| 72 |
|
---|
| 73 | if (adminClient != null) {
|
---|
| 74 | return adminClient.AddProblem(problem);
|
---|
[6130] | 75 | }
|
---|
| 76 |
|
---|
[6160] | 77 | return 0;
|
---|
| 78 | }//AddProblem
|
---|
| 79 |
|
---|
| 80 | public void DeleteProblem(long id) {
|
---|
| 81 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
| 82 |
|
---|
| 83 | if (adminClient != null) {
|
---|
| 84 | adminClient.DeleteProblem(id);
|
---|
[6142] | 85 | }
|
---|
[6160] | 86 | }//DeleteProblem
|
---|
[6142] | 87 |
|
---|
[6160] | 88 | public long SaveProblem(Problem problem) {
|
---|
| 89 | AdministrationServiceClient adminClient = Admin.GetClientFactory();
|
---|
[6130] | 90 |
|
---|
[6160] | 91 | if (adminClient != null) {
|
---|
| 92 | if (problem.Id == 0) {
|
---|
| 93 | return AddProblem(problem);
|
---|
| 94 | }
|
---|
| 95 | else {
|
---|
| 96 | Problem pr = adminClient.GetProblem(problem.Id);
|
---|
[6142] | 97 |
|
---|
[6160] | 98 | if (pr != null) {
|
---|
| 99 | adminClient.UpdateProblem(problem);
|
---|
| 100 | return problem.Id;
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
[6142] | 104 |
|
---|
[6160] | 105 | return 0;
|
---|
| 106 | }//SaveProblem
|
---|
[6130] | 107 | }
|
---|
| 108 | } |
---|