Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/31/10 18:36:51 (14 years ago)
Author:
wtollsch
Message:

#1198 MVC2 plugin template added for HL OKBWebClient

Location:
branches/WebApplication/MVC2/HLWebOKBAdminPlugin
Files:
9 added
1 edited

Legend:

Unmodified
Added
Removed
  • branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Controllers/AlgorithmClassController.cs

    r5081 r5186  
    44using System.Web;
    55using System.Web.Mvc;
     6using HLWebOKBAdminPlugin.ViewModels;
     7using System.Web.Security;
    68using System.ServiceModel.Security;
    7 using HLWebPluginHost.Models;
    8 
    9 namespace HLWebPluginHost.Controllers {
    10     public class AlgorithmClassController : Controller {
    11         //container for data
    12         AlgorithmClassModel viewModel;
     9using HLWebPluginHost.OKBService;
     10
     11namespace HLWebOKBAdminPlugin.Controllers
     12{
     13    public class AlgorithmClassController : Controller
     14    {
     15        //BASICS: controllers respond to input from the browser, decide what to do and return
     16        //        response to the user (Views)
     17
     18        // for edit form 2 controller actions are needed
     19        // first controller action if form is first loaded to display algorithm class data
     20        // second controller handles the post action
     21
     22        //returns a certificated service client for current user .... call this function in every method
     23        private OKBService.OKBServiceClient CertificateValidator() {
     24            OKBService.OKBServiceClient sc = new OKBService.OKBServiceClient();
     25
     26            sc.ClientCredentials.UserName.UserName = Membership.GetUser().UserName;
     27            sc.ClientCredentials.UserName.Password = HttpContext.Session["pwd"].ToString();
     28            sc.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
     29
     30            return sc;
     31        }//CertificateValidator       
     32
    1333        //
    1434        // GET: /AlgorithmClass/
    1535
    1636        public ActionResult Index() {
    17             //create list of algorithms
    18             //OKBService.OKBServiceClient sc = new OKBService.OKBServiceClient();
    19             //sc.ClientCredentials.UserName.UserName = "Gerhard";
    20             //sc.ClientCredentials.UserName.Password = "Gerhard";
    21             //sc.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
    22 
    23             //var agcList = new List<OKBService.AlgorithmClass>();
    24             //OKBService.AlgorithmClass[] ac = sc.GetAlgorithmClasses();
    25             //foreach (OKBService.AlgorithmClass a in ac) {
    26             //    agcList.Add(a);
    27             //}//foreach
    28 
    29             //var viewModel = new AlgorithmClassModel {
    30             //    NumOfClasses = agcList.Count(),
    31             //    AlgorithmClassList = agcList
    32             //};
    33 
    34             viewModel = new AlgorithmClassModel {
    35                 NumOfClasses = 0,
    36                 AlgorithmClassList = null
    37             };           
    38 
    39             return View(viewModel);
    40         }//index
    41 
    42         //
    43         // GET: /AlgorithmClass/Browse
    44 
    45         public string Browse() {
    46             string message = "AlgorithmClass.Browse, id = " + Server.HtmlEncode(Request.QueryString["id"]);
    47             return Server.HtmlEncode(message);
    48         }//index
    49 
    50         //
    51         // GET: /AlgorithmClass/Details/2
    52 
    53         public string Details(int id) {
    54             string message = "AlgorithmClass.Details, id = " + id;
    55             return Server.HtmlEncode(message);
    56         }//index
    57 
    58         //
    59         // GET: /AlgotithmClass/5
    60         public string DelAlgorithmClass(int id) {
    61             string message = "DeleteAlgorithmClass, id = " + Server.HtmlEncode(Request.QueryString["id"]);
    62             return Server.HtmlEncode(message);
    63         }
    64 
    65         public bool AddAlgorithmClass(string name, String description) {
    66             //var viewModel = new AlgorithmClassModel {
    67             //    NumOfClasses = 0,
    68             //    AlgorithmClassList = null
    69             //};
    70 
    71             viewModel.AddAlgorithmClass("ccc", "na");
    72 
    73             return true;
    74 
    75         }//AddAlgorithmClass
     37            //the index action is the homepage of the site (AlgorithmClass) 
     38            //what happens: generate list of AlgorithmClass and commit the list to the index view
     39
     40            //get certificated service client
     41            OKBService.OKBServiceClient sc = CertificateValidator();
     42
     43            //get list of Algorithm Classes
     44            var algorithmClasses = new List<AlgorithmClass>();
     45            AlgorithmClass[] ac = sc.GetAlgorithmClasses();
     46            foreach (AlgorithmClass a in ac) {
     47                algorithmClasses.Add(a);
     48            }//foreach           
     49
     50            //return Index View that contains a list of all AlgorithmClasses (Views/Index.aspx)
     51            return View(algorithmClasses);
     52        }//Index
     53
     54        //
     55        // GET: /AlgorithmClass/Details/5
     56
     57        public ActionResult Details(int id) {
     58            //what happens: get AlgorithmClass object , create a viewmodel which contains the data
     59            //              for the view and commit the viewmodel to the view
     60            //              => correlates to a HTTP GET request
     61
     62            //get certificated service client
     63            OKBService.OKBServiceClient sc = CertificateValidator();
     64
     65            //the viewmodel contains data for the view
     66            var viewModel = new AlgorithmClassViewModel {
     67                AlgorithmClass = sc.GetAlgorithmClass(id)
     68            };
     69
     70            return View(viewModel);
     71        }//Details
     72
     73        //
     74        // GET: /AlgorithmClass/Create
     75
     76        public ActionResult Create() {
     77            //what happens: create empty AlgorithmClass object , create a viewmodel which contains the data
     78            //              for the view and commit the viewmodel to the view
     79            //              this Create action is needed for first time call of the page to display content
     80
     81            //get certificated service client
     82            OKBService.OKBServiceClient sc = CertificateValidator();
     83
     84            //the viewmodel with empty AlgorithmClass object
     85            var viewModel = new AlgorithmClassViewModel {
     86                AlgorithmClass = new AlgorithmClass()
     87            };
     88
     89            return View(viewModel);
     90        }//Create
     91
     92        //
     93        // POST: /AlgorithmClass/Create
     94
     95        [HttpPost]
     96        public ActionResult Create(AlgorithmClass algorithmClass) {
     97            //what happens: the 2nd Create controller handles the POST action from the form
     98            //              an AlgorithmClass object is passed from the Create view by submit
     99
     100            try {
     101                //get certificated service client
     102                OKBService.OKBServiceClient sc = CertificateValidator();
     103
     104                //create new AlgorithmClass object
     105                AlgorithmClass ac = new HLWebPluginHost.OKBService.AlgorithmClass();
     106                ac.Id = algorithmClass.Id;
     107                ac.Name = algorithmClass.Name;
     108                ac.Description = algorithmClass.Description;
     109
     110                //add new AlgorithmClass
     111                sc.AddAlgorithmClass(ac);
     112
     113                //redirect to the home page
     114                return RedirectToAction("Index");
     115            }
     116            catch {
     117                //invalid - redisplay with errors
     118                var viewModel = new AlgorithmClassViewModel {
     119                    AlgorithmClass = algorithmClass
     120                };
     121
     122                return View(viewModel);
     123            }
     124        }//Create - post
     125
     126        //
     127        // GET: /AlgorithmClass/Edit/5
     128
     129        public ActionResult Edit(int id) {
     130            //what happens: get AlgorithmClass object , create a viewmodel which contains the data
     131            //              for the view and commit the viewmodel to the view
     132            //              => correlates to a HTTP GET request
     133           
     134            //get certificated service client
     135            OKBService.OKBServiceClient sc = CertificateValidator();
     136
     137            //the viewmodel contains data for the view
     138            var viewModel = new AlgorithmClassViewModel {
     139                AlgorithmClass = sc.GetAlgorithmClass(id)
     140            };
     141            return View(viewModel);
     142        }//Edit
     143
     144        //
     145        // POST: /AlgorithmClass/Edit/5
     146
     147        [HttpPost]
     148        public ActionResult Edit(int id, FormCollection collection) {
     149            //what happens: the 2nd Edit controller handles the POST action from the form
     150            //              an AlgorithmClass object is passed from the Edit view by submit
     151
     152            //get certificated service client
     153            OKBService.OKBServiceClient sc = CertificateValidator();
     154
     155            //get AlgorithmClass object from DB
     156            var algorithmClass = sc.GetAlgorithmClass(id);
     157
     158            try {
     159                // update AlgorithmClass
     160                UpdateModel(algorithmClass, "AlgorithmClass");
     161
     162                AlgorithmClass ac = new HLWebPluginHost.OKBService.AlgorithmClass();
     163                ac.Id = algorithmClass.Id;
     164                ac.Name = algorithmClass.Name;
     165                ac.Description = algorithmClass.Description;
     166
     167                sc.UpdateAlgorithmClass(ac);
     168
     169                return RedirectToAction("Index");
     170            }
     171            catch {
     172                var viewModel = new AlgorithmClassViewModel {
     173                    AlgorithmClass = algorithmClass
     174                };
     175
     176                return View(viewModel);
     177            }
     178        }//Edit
     179
     180        //
     181        // GET: /AlgorithmClass/Delete/5
     182
     183        public ActionResult Delete(int id) {
     184            //what happens: get AlgorithmClass object , create a viewmodel which contains the data
     185            //              for the view and commit the viewmodel to the view
     186            //              => correlates to a HTTP GET request
     187
     188            //get certificated service client
     189            OKBService.OKBServiceClient sc = CertificateValidator();
     190
     191            //the viewmodel contains data for the view
     192            var viewModel = new AlgorithmClassViewModel {
     193                AlgorithmClass = sc.GetAlgorithmClass(id)
     194            };
     195            return View(viewModel);
     196        }//Delete
     197
     198        //
     199        // POST: /AlgorithmClass/Delete/5
     200
     201        [HttpPost]
     202        public ActionResult Delete(int id, FormCollection collection) {
     203            //what happens: the 2nd Delete controller handles the POST action from the form
     204            //              an AlgorithmClass object is passed from the Delete view by submit
     205   
     206            //get certificated service client
     207            OKBService.OKBServiceClient sc = CertificateValidator();
     208
     209            //load object from db
     210            var algorithmClass = sc.GetAlgorithmClass(id);
     211
     212            try {
     213                //delete object
     214                sc.DeleteAlgorithmClass(id);
     215
     216                return RedirectToAction("Index");
     217            }
     218            catch {
     219                var viewModel = new AlgorithmClassViewModel {
     220                    AlgorithmClass = algorithmClass
     221                };
     222
     223                return View(viewModel);
     224            }
     225        }//Delete
    76226
    77227    }
Note: See TracChangeset for help on using the changeset viewer.