Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. @modelIEnumerable<MyApp.Models.ComputerDetail>
  2. @{
  3. ViewBag.Title = "Index";
  4. }
  5.  
  6. <h2 class ="page-header">Computer Details</h2>
  7.  
  8. <div class ="col-lg-12">
  9. <p>
  10. @Html.ActionLink("Create New", "Create", "ComputerDetail", new {id = Model.First().ComputerID}, new { @class = "btn btn-default"})
  11. </p>
  12. <div class="panel panel-default">
  13. <div class ="panel-body">
  14. <table class ="table table-striped" id="dtaTable">
  15. <thead class ="dataTableHead">
  16. <tr>
  17. <th>
  18. @Html.DisplayNameFor(model => model.ComputerID)
  19. </th>
  20. <th>
  21. @Html.DisplayNameFor(model => model.EmployeeID)
  22. </th>
  23. <th>
  24. @Html.DisplayNameFor(model => model.StartDate)
  25. </th>
  26. <th>
  27. @Html.DisplayNameFor(model => model.EndDate)
  28. </th>
  29. <th>
  30. @Html.DisplayNameFor(model => model.Comments)
  31. </th>
  32. <th>Actions</th>
  33. </tr>
  34. </thead>
  35.  
  36. @foreach (var item in Model) {
  37. <tr>
  38. <td>
  39. @Html.DisplayFor(modelItem => item.ComputerID)
  40. </td>
  41. <td>
  42. @Html.DisplayFor(modelItem => item.Employee.FullName)
  43. </td>
  44. <td>
  45. @Html.DisplayFor(modelItem => item.StartDate)
  46. </td>
  47. <td>
  48. @Html.DisplayFor(modelItem => item.EndDate)
  49. </td>
  50. <td>
  51. @Html.DisplayFor(modelItem => item.Comments)
  52. </td>
  53. <td>
  54. @Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
  55. @Html.ActionLink("Details", "Details", new { id=item.ID }) |
  56. @Html.ActionLink("Delete", "Delete", new { id=item.ID })
  57. </td>
  58. </tr>
  59. }
  60. </table>
  61. </div>
  62. </div>
  63. </div>
  64.  
  65. public ActionResult Index(int id)
  66. {
  67. var _FindComputerID = GetComputerDetails(id);
  68. return View(_FindComputerID);
  69. }
  70.  
  71. private List<ComputerDetail>GetComputerDetails(int id)
  72. {
  73. var FindComputerID = db.ComputerDetails.Where(cd => cd.ComputerID == id).Include
  74. (cd => cd.Employee).OrderByDescending(cd => cd.ID);
  75.  
  76. return FindComputerID.ToList();
  77. }
  78.  
  79. [HttpGet]
  80. public ActionResult Create(int id)
  81. {
  82. ComputerDetail computerdetail = new ComputerDetail ();
  83. computerdetail.ComputerID = id;
  84.  
  85. return View(computerdetail);
  86. }
  87.  
  88. public class ComputerDetail
  89. {
  90. [Key]
  91. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  92. public int ID { get; set; }
  93.  
  94. [Required(ErrorMessage = "Please enter service tag")]
  95. [Display(Name = "Service Tag")]
  96. public int ComputerID { get; set; }
  97.  
  98. [Required(ErrorMessage = "Please select employee name")]
  99. [Display(Name = "Employee Name")]
  100. public int EmployeeID { get; set; }
  101.  
  102. [Required(ErrorMessage = "Please enter date")]
  103. [Display(Name = "Date Bought")]
  104. [DataType(DataType.Date)]
  105. public DateTime StartDate { get; set; }
  106.  
  107. [Display(Name = "Date Bought")]
  108. [DataType(DataType.Date)]
  109. public DateTime? EndDate { get; set; }
  110.  
  111. public string Comments { get; set; }
  112.  
  113. //references
  114. public virtual Assets.Computer Computer { get; set; }
  115. public virtual Employee Employee { get; set; }
  116.  
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement