Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jan 26th, 2013  |  syntax: None  |  size: 5.57 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class TrainingListEmployeesViewModel : BaseTrainingViewModel
  2. {
  3.     public TrainingListEmployeesViewModel()
  4.     {
  5.         this.EmployeeList = new List<int>();
  6.         this.ClientEmployeeSelector = new ClientEmployeeSelector();
  7.     }
  8.  
  9.     public TrainingListEmployeesViewModel(List<int> employeeList, string trainingName, string trainingDescription)
  10.         : base(trainingName, trainingDescription)
  11.     {
  12.         this.EmployeeList = employeeList;
  13.         var dates = new CalendarDates(Utility.GetToday(), Utility.GetToday().AddYears(1));
  14.         this.Cvm = new CalendarViewModel(employeeList.ToList(), dates);
  15.     }
  16.  
  17.     public List<int> EmployeeList { get; set; }
  18.  
  19.     public ClientEmployeeSelector ClientEmployeeSelector { get; set; }
  20. }
  21.        
  22. [HttpPost]
  23.         [Authorize(Roles = "Administrator, Trainer, ManagerAccounts, ManagerIT")]
  24.         [ValidateAntiForgeryToken]
  25.         [ValidateOnlyIncomingValuesAttribute]
  26.         public ActionResult Training(TrainingViewModel tvm)
  27.         {
  28.             SessionObjects.TrainingName = tvm.TrainingName;
  29.             SessionObjects.TrainingDescription = tvm.TrainingDescription;
  30.             return this.RedirectToAction("Training", new { employeeId = tvm.EmployeeSelector.SearchTextId });
  31.         }
  32.  
  33.         [HttpGet]
  34.         [Authorize(Roles = "Administrator, Trainer, ManagerAccounts, ManagerIT")]
  35.         public ActionResult BulkTraining()
  36.         {
  37.             return this.View(new TrainingListEmployeesViewModel());
  38.         }
  39.        
  40. <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<SHP.Models.TrainingListEmployeesViewModel>" %>
  41. <%@ Import Namespace="System.Web.Script.Serialization" %>
  42.  
  43. <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
  44.     Bulk Training
  45. </asp:Content>
  46.  
  47. <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
  48. <form class="employeeListEditor">
  49.     <h3>Allocate or cancel training for the selected employees</h3>
  50.     <table>
  51.         <tr>
  52.             <td style="text-align: right;">Course Name</td>
  53.             <td><%: Html.EditorFor(model => model.TrainingName) %></td>
  54.         </tr>
  55.         <tr>
  56.             <td style="text-align: right;">Description (optional)</td>
  57.             <td><%: Html.TextAreaFor(
  58.                model => model.TrainingDescription, new { maxlength = "255", style = "width:400px;height:100px;" }) %></td>
  59.         </tr>
  60.     </table>
  61.     <%: Html.EditorFor(model => model.ClientEmployeeSelector) %>
  62.     <button data-bind="click: addEmployee">Add</button>
  63.     <div id="displayEmployees" style="margin-top:10px;display: block">
  64.         <table id="employeeDataTable" class="groupBorder">
  65.             <thead>
  66.                 <tr>
  67.                     <th></th>
  68.                     <th>Employee</th>
  69.                 </tr>
  70.             </thead>
  71.             <tbody data-bind="foreach: employees">
  72.                 <tr>
  73.                     <td>
  74.                         <a href="#" data-bind="click: function() { viewModel.removeEmployee($data) }">Remove</a>
  75.                         <input type="hidden" data-bind="value: searchTextId"/>
  76.                     </td>
  77.                     <td><span data-bind="value: searchText"></span></td>
  78.                 </tr>              
  79.             </tbody>
  80.         </table>
  81.     </div>
  82. </form>
  83.  
  84.     <script type="text/javascript">
  85.         function Employee(id, text) {
  86.             var self = this;
  87.             self.searchId = id;
  88.             self.searchText = text;
  89.         }
  90.  
  91.         var initialData = <%= new JavaScriptSerializer().Serialize(Model) %>;
  92.         function ViewModel() {
  93.             var self = this;
  94.             self.employees = ko.observableArray(initialData.EmployeeList);
  95.             self.searchText = ko.observable(initialData.SearchText);
  96.             self.searchTextId = ko.observable(initialData.SearchTextId);
  97.             self.removeEmployee = function(employee) {
  98.                 this.employees.remove(employee);
  99.             };
  100.             self.addEmployee = function() {
  101.                 alert(self.searchText);
  102.                 this.employees.push(new Employee(self.searchTextId, self.searchText));
  103.             };
  104.             self.save = function() {
  105.                 ko.utils.postJson(location.href, { employees: self.employees });
  106.             };
  107.         }
  108.         ko.applyBindings(new ViewModel());
  109.     </script>
  110. </asp:Content>
  111.        
  112. <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<SHP.Models.ClientEmployeeSelector>" %>
  113.  
  114.         <table class="groupBorder">
  115.             <tr>
  116.                 <th colspan="2">Enter 2 or more characters for "<%: Html.LabelFor(model => model.SearchText)%>" and select from the list.</th>
  117.             </tr>
  118.             <tr>
  119.                 <td><%: Html.LabelFor(model => model.SearchText)%></td>
  120.                 <td><%: Html.AutocompleteFor(model => model.SearchText, controller: "Payroll",
  121.                                             minLength: 2, maxResults: 10,
  122.                                             htmlAttributes: new { style = "color:purple; width:500px;" })%>
  123.                                 <%: Html.HiddenFor(model => model.SearchTextId)%>
  124.                                 <%: Html.HiddenFor(model => model.SearchText)%>
  125.                 </td>
  126.             </tr>
  127.         </table>
  128.        
  129. <tbody data-bind="foreach: employees">
  130.         <tr>
  131.             <td>
  132.                 <a href="#" data-bind="click: $parent.removeEmployee">Remove</a>
  133.                 <input type="hidden" data-bind="value: searchId"/>
  134.             </td>
  135.             <td><span data-bind="text: searchText"></span></td>
  136.         </tr>              
  137.     </tbody>
  138.        
  139. <input type="hidden" data-bind="value: $parent.searchTextId"/>