Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Models/AlgorithmModel.cs @ 11194

Last change on this file since 11194 was 6246, checked in by wtollsch, 14 years ago

#1433 AlgorithmClass, Algorithm, ProblemClass, Problem create/update appropriate controller/models/views, File upload (Algorithm / Problem)

File size: 4.0 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{
10    public class AlgorithmModel {
11
12        public String SelectedSubMenu { get; set; }
13        public IList<Algorithm> Algorithms { get { return AlgorithmGetAll(); } set { ;} }
14        public IList<AlgorithmClass> AlgorithmClasses { get { return AlgorithmClassGetAll(); } }
15        public IList<Platform> Platforms { get { return PlatformsGetAll(); } }
16
17        public Algorithm Algorithm { get; set; }
18
19        public AlgorithmModel() {
20            Algorithm = new Algorithm();
21        }//AlgorithmModel
22
23        //***************************************Algorithms***************************************************
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        }//AlgorithmClassGetAll
38
39        private IList<AlgorithmClass> AlgorithmClassGetAll() {
40            AdministrationServiceClient adminClient = Admin.GetClientFactory();
41
42            IList<AlgorithmClass> algorithmClassList = new List<AlgorithmClass>();
43
44            if (adminClient != null) {
45                AlgorithmClass[] algorithmClasses = adminClient.GetAlgorithmClasses();
46                foreach(AlgorithmClass ac in algorithmClasses) {
47                    algorithmClassList.Add(ac);
48                }
49            }//if (adminClient != null)
50
51            return algorithmClassList;
52        }//AlgorithmClassGetAll
53
54        private IList<Algorithm> AlgorithmGetAll() {
55            AdministrationServiceClient adminClient = Admin.GetClientFactory();
56
57            IList<Algorithm> algorithmList = new List<Algorithm>();
58
59            if (adminClient != null) {
60                Algorithm[] algorithm = adminClient.GetAlgorithms();
61                foreach(Algorithm alg in algorithm) {
62                    algorithmList.Add(alg);
63
64                }
65            }//if (adminClient != null)
66
67            return algorithmList;
68        }//AlgorithmGetAll
69
70        private long AddAlgorithm(Algorithm algorithm) {
71            AdministrationServiceClient adminClient = Admin.GetClientFactory();
72
73            if (adminClient != null) {
74                return adminClient.AddAlgorithm(algorithm);
75            }
76
77            return 0;
78        }//AddAlgorithm
79
80        public void DeleteAlgorithm(long id) {
81            AdministrationServiceClient adminClient = Admin.GetClientFactory();
82
83            if (adminClient != null) {
84                adminClient.DeleteAlgorithm(id);
85            }
86        }//DeleteAlgorithm
87
88        public long SaveAlgorithm(Algorithm algorithm) {
89            AdministrationServiceClient adminClient = Admin.GetClientFactory();
90
91            if (adminClient != null) {
92                if (algorithm.Id == 0) {
93                    return AddAlgorithm(algorithm);
94                }
95                else {
96                    Algorithm alg = adminClient.GetAlgorithm(algorithm.Id);
97
98                    if (alg != null) {
99                        adminClient.UpdateAlgorithm(algorithm);
100                        return algorithm.Id;
101                    }
102                }
103            }
104
105            return 0;
106        }//SaveAlgorithm
107
108        public void UpdateAlgorithmData(long id, byte[] data) {
109            AdministrationServiceClient adminClient = Admin.GetClientFactory();
110
111            if (adminClient != null) {
112                adminClient.UpdateAlgorithmData(id, data);
113            }
114        }//UpdateProblemData
115    }
116}
Note: See TracBrowser for help on using the repository browser.