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