Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.78 KB | None | 0 0
  1. public partial class tblEquipamento
  2. {
  3. public tblEquipamento()
  4. {
  5. this.tblEquipamentoSoftware = new HashSet<tblEquipamentoSoftware>();
  6. }
  7. [Key]
  8. public int equIdEquipamento { get; set; }
  9. [Required(ErrorMessage = "Informe o NIP do Equipamento")]
  10. [Display(Name = "NIP")]
  11. public string equNip { get; set; }
  12.  
  13. public virtual ICollection<tblEquipamentoSoftware> tblEquipamentoSoftware { get; set; }
  14. }
  15.  
  16. public partial class tblEquipamentoSoftware
  17. {
  18. [Key, Column(Order = 0)]
  19. [Display(Name = "NIP")]
  20. public int eqsIdEquipamento { get; set; }
  21. [Key, Column(Order = 1)]
  22. [Display(Name = "Software")]
  23. public int eqsIdSoftware { get; set; }
  24. [Required(ErrorMessage = "Informe o Tipo")]
  25. [Display(Name = "Tipo")]
  26. public string eqsTipo { get; set; }
  27.  
  28. public virtual tblEquipamento tblEquipamento { get; set; }
  29. public virtual tblSoftware tblSoftware { get; set; }
  30. }
  31.  
  32. public partial class tblSoftware
  33. {
  34. public tblSoftware()
  35. {
  36. this.tblEquipamentoSoftware = new HashSet<tblEquipamentoSoftware>();
  37. }
  38.  
  39. public int sofIdSoftware { get; set; }
  40. [Required(ErrorMessage = "Informe o software")]
  41. [Display(Name = "Nome")]
  42. public string sofNome { get; set; }
  43.  
  44. public virtual ICollection<tblEquipamentoSoftware> tblEquipamentoSoftware { get; set; }
  45.  
  46. public ActionResult Create()
  47. {
  48. //Eu Adicionei essa parte aqui do ViewBag pq me basei em um tutorial, mas se estiver errado peço que me avisem pfvr
  49. ViewBag.eqsIdSoftware = new SelectList(db.tblSoftware, "sofIdSoftware", "sofNome");
  50. return View();
  51. }
  52.  
  53. [HttpPost]
  54. [ValidateAntiForgeryToken]
  55. public ActionResult Create([Bind(Include = "equIdEquipamento,equNip, tblEquipamentoSoftware")] tblEquipamento tblEquipamento)
  56. {
  57. if (ModelState.IsValid)
  58. {
  59. db.tblEquipamento.Add(tblEquipamento);
  60. db.SaveChanges();
  61. return RedirectToAction("Index");
  62. }
  63. ViewBag.eqsIdSoftware = new SelectList(db.tblSoftware, "sofIdSoftware", "sofNome", tblEquipamento.tblEquipamentoSoftware);
  64. return View(tblEquipamento);
  65. }
  66. public ActionResult NovoSoftwareEquipamento()
  67. {
  68. tblEquipamento equ = new tblEquipamento();
  69. return PartialView("_SoftwareEquipamento", new tblEquipamentoSoftware { eqsIdEquipamento = equ.equIdEquipamento});
  70. }
  71.  
  72. @using (Html.BeginForm())
  73. {
  74. @Html.AntiForgeryToken()
  75.  
  76. <div class="form-horizontal">
  77. <h4>tblEquipamento</h4>
  78. <hr />
  79. @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  80. <div class="form-group col-lg-4">
  81. @Html.LabelFor(model => model.equNip, htmlAttributes: new { @class = "control-label col-md-2" })
  82. <div class="col-lg-9">
  83. @Html.EditorFor(model => model.equNip, new { htmlAttributes = new { @class = "form-control" } })
  84. @Html.ValidationMessageFor(model => model.equNip, "", new { @class = "text-danger" })
  85. </div>
  86. </div>
  87.  
  88. @Html.Partial("_Softwares")
  89.  
  90. <div class="form-group">
  91. <div class="col-md-offset-2 col-md-10">
  92. <input type="submit" value="Cadastrar" class="btn btn-success" />
  93. </div>
  94. </div>
  95. </div>
  96. }
  97.  
  98. @model IEnumerable<TesteCadastroAtivo.Models.tblEquipamentoSoftware>
  99.  
  100. <div class="actions">
  101. <button type="button" class="btn btn-default btn-sm" id="adicionar-novo-software">
  102. Adicionar Software
  103. </button>
  104. </div>
  105.  
  106. <div id="area-software">
  107. @if (Model != null)
  108. {
  109. foreach (var software in Model)
  110. {
  111. @Html.Partial("_SoftwareEquipamento", software);
  112. }
  113. }
  114. </div>
  115.  
  116. <script src="~/Scripts/jquery-1.8.0.min.js"></script>
  117. <script src="~/Scripts/jquery.validate.min.js"></script>
  118. <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
  119. <script type="text/javascript">
  120. $(document).ready(function(){
  121. $("#adicionar-novo-software").click(function () {
  122. $.get('/Equipamento/NovoSoftwareEquipamento', function (template) {
  123. $("#area-software").append(template);
  124. });
  125. });
  126. });
  127. </script>
  128.  
  129. @model TesteCadastroAtivo.Models.tblEquipamentoSoftware
  130.  
  131. @using (Html.BeginCollectionItem("tblEquipamentoSoftware"))
  132. {
  133. <div class="form-group">
  134. @Html.HiddenFor(model => model.eqsIdEquipamento)
  135. @Html.HiddenFor(model => model.eqsIdSoftware)
  136.  
  137. <div class="form-group">
  138. @Html.LabelFor(model => model.eqsTipo, htmlAttributes: new { @class = "control-label col-md-2" })
  139. <div class="col-md-10">
  140. @Html.EditorFor(model => model.eqsTipo, new { htmlAttributes = new { @class = "form-control" } })
  141. @Html.ValidationMessageFor(model => model.eqsTipo, "", new { @class = "text-danger" })
  142. </div>
  143. </div>
  144.  
  145. <div class="col-md-1">
  146. <a class="btn red" onclick="$(this).parent().parent().remove();">Excluir</a>
  147. </div>
  148. </div>
  149. }
  150.  
  151. <div class="form-group">
  152. @Html.LabelFor(model => model.eqsIdSoftware, "eqsIdSoftware", htmlAttributes: new { @class = "control-label col-md-2" })
  153. <div class="col-md-10">
  154. @Html.DropDownList("eqsIdSoftware", null, htmlAttributes: new { @class = "form-control" })
  155. @Html.ValidationMessageFor(model => model.eqsIdSoftware, "", new { @class = "text-danger" })
  156. </div>
  157. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement