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
Files:
13 added
2 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    }
  • branches/WebApplication/MVC2/HeuristicLabWeb.PluginHost/HLWebPluginHost/Views/AlgorithmClass/Index.aspx

    r4952 r5186  
    1 <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
    2 
    3 <script runat="server">
    4 
    5     void lbAlgorithmClassOnClick(object sender, EventArgs e) {
    6       txtName.Text = "aaa";
    7    }
    8 
    9 </script>
    10 
    11 
     1<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<HLWebPluginHost.OKBService.AlgorithmClass>>" %>
     2<%@ Import Namespace="HLWebOKBAdminPlugin.Helpers" %>
    123<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    134  Index
    145</asp:Content>
    15    
    166
    177<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    188
    19     <form id="form1" runat="server">
     9    <h2>Index</h2>
    2010
     11    <table>
     12        <tr>
     13            <th></th>
     14            <th>
     15                Description
     16            </th>
     17            <th>
     18                Name
     19            </th>
     20            <th>
     21                Id
     22            </th>
     23        </tr>
    2124
    22     <h2>AlgorithmClasses</h2>
     25    <% foreach (var item in Model) { %>
    2326   
    24     <%--<ul>
    25         <%foreach (HLWebPluginHost.OKBService.AlgorithmClass ac in Model.AlgorithmClassList) { %>
    26             <li>
    27                 <%: ac.Name %>
    28             </li>
    29         <%} %>
    30     </ul>--%>
     27        <tr>
     28            <td>
     29                <%: Html.ActionLink("Edit", "Edit", new { id=item.Id }) %> |
     30                <%: Html.ActionLink("Details", "Details", new { id=item.Id })%> |
     31                <%: Html.ActionLink("Delete", "Delete", new { id = item.Id })%>
     32            </td>
     33            <td>
     34                <%: Html.Truncate(item.Description,25) %>
     35            </td>
     36            <td>
     37                <%: Html.Truncate(item.Name, 25)%>
     38            </td>
     39            <td>
     40                <%: item.Id %>
     41            </td>
     42        </tr>
    3143   
    32     <asp:Panel ID="Panel1" runat="server">
    33         <asp:ImageButton ID="btnAddAlgorithmClass" runat="server"
    34             ImageUrl="~/Resources/Plus.bmp" ToolTip="Add Class" BorderColor="Black"
    35             CommandArgument="Id" CommandName="AddAlgorithmClass" />
    36         <asp:ImageButton ID="btnDeleteAlgorithmClass" runat="server"
    37             ImageUrl="~/Resources/Delete.bmp" ToolTip="Delete Class"
    38             CommandArgument="Id" CommandName="lgorithmClass" />
    39         <asp:ImageButton ID="btnUpdateAlgorithmClass" runat="server"
    40             CommandArgument="Id" CommandName="UpdAlgorithmClass"
    41             ImageUrl="~/Resources/Update.bmp" />
    42     </asp:Panel>
     44    <% } %>
     45
     46    </table>
     47
    4348    <p>
    44         <asp:ListBox ID="lbAlgorithmClass" runat="server" DataSourceID="ODSAlgorithmClasses"
    45             DataTextField="Name" DataValueField="Id" Height="350px" style="margin-top: 0px"
    46             Width="246px">
    47         </asp:ListBox>
    48         <asp:ObjectDataSource ID="ODSAlgorithmClasses" runat="server"
    49             SelectMethod="AlgorithmClassGetAll"
    50             TypeName="HLWebPluginHost.Models.AlgorithmClassModel">
    51         </asp:ObjectDataSource>
    52         <asp:Button ID="Button1" Text="Select" OnClick="lbAlgorithmClassOnClick" runat="server"/>
    53 
     49        <%: Html.ActionLink("Create New", "Create") %>
    5450    </p>
    55    
    56 
    57     <asp:Panel ID="Panel2" runat="server" Height="139px">
    58         <asp:Label ID="lbName" runat="server" Text="Name:"></asp:Label>
    59         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    60         <asp:TextBox ID="txtName" runat="server" Width="197px"></asp:TextBox>
    61         <br />
    62         Description:
    63         <asp:TextBox ID="txtDescription" runat="server" Width="197px"></asp:TextBox>
    64     </asp:Panel>
    65    
    66 
    67     </form>
    68 
    69    
    7051
    7152</asp:Content>
     53
Note: See TracChangeset for help on using the changeset viewer.