Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Controllers/AlgorithmClassController.cs @ 5757

Last change on this file since 5757 was 5700, checked in by wtollsch, 14 years ago

#1433 adjusted HLWebOKBAdminPlugin to new Service (AdministrationService)

File size: 9.8 KB
RevLine 
[4985]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.Mvc;
[5186]6using HLWebOKBAdminPlugin.ViewModels;
7using System.Web.Security;
[4985]8using System.ServiceModel.Security;
[5700]9//using HLWebPluginHost.OKBService;
[5258]10using System.Diagnostics;
[5700]11using HLWebOKBAdminPlugin.OKBAdministrationService;
12using HLWebOKBAdminPlugin.OKBAuthenticationService;
[4985]13
[5186]14namespace HLWebOKBAdminPlugin.Controllers
15{
16    public class AlgorithmClassController : Controller
17    {
18        //BASICS: controllers respond to input from the browser, decide what to do and return
19        //        response to the user (Views)
20
21        // for edit form 2 controller actions are needed
22        // first controller action if form is first loaded to display algorithm class data
23        // second controller handles the post action
24
25        //returns a certificated service client for current user .... call this function in every method
[5700]26                         
27        //private OKBService.OKBServiceClient CertificateValidator() {
28        //    OKBService.OKBServiceClient sc = new OKBService.OKBServiceClient();
29        //    sc.ClientCredentials.UserName.UserName = Membership.GetUser().UserName;
30        //    //sc.ClientCredentials.UserName.Password = HttpContext.Session["pwd"].ToString();
31        //    sc.ClientCredentials.UserName.Password = "Gerhard";
32        //    sc.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
[5186]33
[5700]34        //    return sc;
35        //}//CertificateValidator   
[5186]36
[5700]37        private AdministrationServiceClient CertificateValidator() {
38            AdministrationServiceClient asc = new AdministrationServiceClient();
[5186]39
[5700]40            asc.ClientCredentials.UserName.UserName = Membership.GetUser().UserName;
41            //asc.ClientCredentials.UserName.Password = HttpContext.Session["pwd"].ToString();
42            asc.ClientCredentials.UserName.Password = "Gerhard";
43            asc.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
44
45            return asc;
46        }//CertificateValidator
47
[4985]48        //
49        // GET: /AlgorithmClass/
50
51        public ActionResult Index() {
[5186]52            //the index action is the homepage of the site (AlgorithmClass) 
53            //what happens: generate list of AlgorithmClass and commit the list to the index view
[4985]54
[5258]55           
56
[5186]57            //get certificated service client
[5700]58            AdministrationServiceClient asc = CertificateValidator();                       
[4985]59
[5258]60            var tstModel = new AlgorithmClassViewModel {
61                AlgorithmClass = new AlgorithmClass()
62            };
63
64            Debug.WriteLine("tstModel created");
65
[5186]66            //get list of Algorithm Classes
67            var algorithmClasses = new List<AlgorithmClass>();
[5700]68            AlgorithmClass[] ac = asc.GetAlgorithmClasses();
[5186]69            foreach (AlgorithmClass a in ac) {
70                algorithmClasses.Add(a);
71            }//foreach           
[4985]72
[5186]73            //return Index View that contains a list of all AlgorithmClasses (Views/Index.aspx)
74            return View(algorithmClasses);
75        }//Index
[4985]76
[5186]77        //
78        // GET: /AlgorithmClass/Details/5
79
80        public ActionResult Details(int id) {
81            //what happens: get AlgorithmClass object , create a viewmodel which contains the data
82            //              for the view and commit the viewmodel to the view
83            //              => correlates to a HTTP GET request
84
85            //get certificated service client
[5700]86            AdministrationServiceClient asc = CertificateValidator();
[5186]87
88            //the viewmodel contains data for the view
89            var viewModel = new AlgorithmClassViewModel {
[5700]90                AlgorithmClass = asc.GetAlgorithmClass(id)
[5186]91            };
92
[5258]93            ViewData["AlgorithmClass"] = viewModel;
94
95            return View();
[5186]96        }//Details
[4985]97
98        //
[5186]99        // GET: /AlgorithmClass/Create
[4985]100
[5186]101        public ActionResult Create() {
102            //what happens: create empty AlgorithmClass object , create a viewmodel which contains the data
103            //              for the view and commit the viewmodel to the view
104            //              this Create action is needed for first time call of the page to display content
[4985]105
[5186]106            //get certificated service client
[5700]107            AdministrationServiceClient asc = CertificateValidator();
[5186]108
109            //the viewmodel with empty AlgorithmClass object
110            var viewModel = new AlgorithmClassViewModel {
111                AlgorithmClass = new AlgorithmClass()
112            };
113
[5258]114            ViewData["AlgorithmClass"] = viewModel;
115
116            return View();
[5186]117        }//Create
118
[4985]119        //
[5186]120        // POST: /AlgorithmClass/Create
[4985]121
[5186]122        [HttpPost]
123        public ActionResult Create(AlgorithmClass algorithmClass) {
124            //what happens: the 2nd Create controller handles the POST action from the form
125            //              an AlgorithmClass object is passed from the Create view by submit
[4985]126
[5186]127            try {
128                //get certificated service client
[5700]129                AdministrationServiceClient asc = CertificateValidator();
[5186]130
131                //create new AlgorithmClass object
[5700]132                AlgorithmClass ac = new AlgorithmClass();
[5186]133                ac.Id = algorithmClass.Id;
134                ac.Name = algorithmClass.Name;
135                ac.Description = algorithmClass.Description;
136
137                //add new AlgorithmClass
[5700]138                asc.AddAlgorithmClass(ac);
[5186]139
140                //redirect to the home page
141                return RedirectToAction("Index");
142            }
143            catch {
144                //invalid - redisplay with errors
145                var viewModel = new AlgorithmClassViewModel {
146                    AlgorithmClass = algorithmClass
147                };
148
[5258]149                ViewData["AlgorithmClass"] = viewModel;
150
151                return View();
[5186]152            }
153        }//Create - post
154
[4985]155        //
[5186]156        // GET: /AlgorithmClass/Edit/5
[4985]157
[5186]158        public ActionResult Edit(int id) {
159            //what happens: get AlgorithmClass object , create a viewmodel which contains the data
160            //              for the view and commit the viewmodel to the view
161            //              => correlates to a HTTP GET request
162           
163            //get certificated service client
[5700]164            AdministrationServiceClient asc = CertificateValidator();
[4985]165
[5186]166            //the viewmodel contains data for the view
167            var viewModel = new AlgorithmClassViewModel {
[5700]168                AlgorithmClass = asc.GetAlgorithmClass(id)
[5186]169            };
[5258]170
171            ViewData["AlgorithmClass"] = viewModel;
172
173            return View();
[5186]174        }//Edit
[4985]175
[5186]176        //
177        // POST: /AlgorithmClass/Edit/5
[4985]178
[5186]179        [HttpPost]
180        public ActionResult Edit(int id, FormCollection collection) {
181            //what happens: the 2nd Edit controller handles the POST action from the form
182            //              an AlgorithmClass object is passed from the Edit view by submit
[4985]183
[5186]184            //get certificated service client
[5700]185            AdministrationServiceClient asc = CertificateValidator();
[5186]186
187            //get AlgorithmClass object from DB
[5700]188            var algorithmClass = asc.GetAlgorithmClass(id);
[5186]189
190            try {
191                // update AlgorithmClass
192                UpdateModel(algorithmClass, "AlgorithmClass");
193
[5700]194                AlgorithmClass ac = new AlgorithmClass();
[5186]195                ac.Id = algorithmClass.Id;
196                ac.Name = algorithmClass.Name;
197                ac.Description = algorithmClass.Description;
198
[5700]199                asc.UpdateAlgorithmClass(ac);
[5186]200
201                return RedirectToAction("Index");
202            }
203            catch {
204                var viewModel = new AlgorithmClassViewModel {
205                    AlgorithmClass = algorithmClass
206                };
207
[5258]208                ViewData["AlgorithmClass"] = viewModel;
209
210                return View();
[5186]211            }
212        }//Edit
213
214        //
215        // GET: /AlgorithmClass/Delete/5
216
217        public ActionResult Delete(int id) {
218            //what happens: get AlgorithmClass object , create a viewmodel which contains the data
219            //              for the view and commit the viewmodel to the view
220            //              => correlates to a HTTP GET request
221
222            //get certificated service client
[5700]223            AdministrationServiceClient asc = CertificateValidator();
[5186]224
225            //the viewmodel contains data for the view
226            var viewModel = new AlgorithmClassViewModel {
[5700]227                AlgorithmClass = asc.GetAlgorithmClass(id)
[5186]228            };
[5258]229
230            ViewData["AlgorithmClass"] = viewModel;
231
232            return View();
[5186]233        }//Delete
234
235        //
236        // POST: /AlgorithmClass/Delete/5
237
238        [HttpPost]
239        public ActionResult Delete(int id, FormCollection collection) {
240            //what happens: the 2nd Delete controller handles the POST action from the form
241            //              an AlgorithmClass object is passed from the Delete view by submit
242   
243            //get certificated service client
[5700]244            AdministrationServiceClient asc = CertificateValidator();
[5186]245
246            //load object from db
[5700]247            var algorithmClass = asc.GetAlgorithmClass(id);
[5186]248
249            try {
250                //delete object
[5700]251                asc.DeleteAlgorithmClass(id);
[5186]252
253                return RedirectToAction("Index");
254            }
255            catch {
256                var viewModel = new AlgorithmClassViewModel {
257                    AlgorithmClass = algorithmClass
258                };
259
[5258]260                ViewData["AlgorithmClass"] = viewModel;
261
262                return View();
[5186]263            }
264        }//Delete
265
[4985]266    }
267}
Note: See TracBrowser for help on using the repository browser.