Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class tblEquipamento
- {
- public tblEquipamento()
- {
- this.tblEquipamentoSoftware = new HashSet<tblEquipamentoSoftware>();
- }
- [Key]
- public int equIdEquipamento { get; set; }
- [Required(ErrorMessage = "Informe o NIP do Equipamento")]
- [Display(Name = "NIP")]
- public string equNip { get; set; }
- public virtual ICollection<tblEquipamentoSoftware> tblEquipamentoSoftware { get; set; }
- }
- public partial class tblEquipamentoSoftware
- {
- [Key, Column(Order = 0)]
- [Display(Name = "NIP")]
- public int eqsIdEquipamento { get; set; }
- [Key, Column(Order = 1)]
- [Display(Name = "Software")]
- public int eqsIdSoftware { get; set; }
- [Required(ErrorMessage = "Informe o Tipo")]
- [Display(Name = "Tipo")]
- public string eqsTipo { get; set; }
- public virtual tblEquipamento tblEquipamento { get; set; }
- public virtual tblSoftware tblSoftware { get; set; }
- }
- public partial class tblSoftware
- {
- public tblSoftware()
- {
- this.tblEquipamentoSoftware = new HashSet<tblEquipamentoSoftware>();
- }
- public int sofIdSoftware { get; set; }
- [Required(ErrorMessage = "Informe o software")]
- [Display(Name = "Nome")]
- public string sofNome { get; set; }
- public virtual ICollection<tblEquipamentoSoftware> tblEquipamentoSoftware { get; set; }
- public ActionResult Create()
- {
- //Eu Adicionei essa parte aqui do ViewBag pq me basei em um tutorial, mas se estiver errado peço que me avisem pfvr
- ViewBag.eqsIdSoftware = new SelectList(db.tblSoftware, "sofIdSoftware", "sofNome");
- return View();
- }
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Create([Bind(Include = "equIdEquipamento,equNip, tblEquipamentoSoftware")] tblEquipamento tblEquipamento)
- {
- if (ModelState.IsValid)
- {
- db.tblEquipamento.Add(tblEquipamento);
- db.SaveChanges();
- return RedirectToAction("Index");
- }
- ViewBag.eqsIdSoftware = new SelectList(db.tblSoftware, "sofIdSoftware", "sofNome", tblEquipamento.tblEquipamentoSoftware);
- return View(tblEquipamento);
- }
- public ActionResult NovoSoftwareEquipamento()
- {
- tblEquipamento equ = new tblEquipamento();
- return PartialView("_SoftwareEquipamento", new tblEquipamentoSoftware { eqsIdEquipamento = equ.equIdEquipamento});
- }
- @using (Html.BeginForm())
- {
- @Html.AntiForgeryToken()
- <div class="form-horizontal">
- <h4>tblEquipamento</h4>
- <hr />
- @Html.ValidationSummary(true, "", new { @class = "text-danger" })
- <div class="form-group col-lg-4">
- @Html.LabelFor(model => model.equNip, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-lg-9">
- @Html.EditorFor(model => model.equNip, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.equNip, "", new { @class = "text-danger" })
- </div>
- </div>
- @Html.Partial("_Softwares")
- <div class="form-group">
- <div class="col-md-offset-2 col-md-10">
- <input type="submit" value="Cadastrar" class="btn btn-success" />
- </div>
- </div>
- </div>
- }
- @model IEnumerable<TesteCadastroAtivo.Models.tblEquipamentoSoftware>
- <div class="actions">
- <button type="button" class="btn btn-default btn-sm" id="adicionar-novo-software">
- Adicionar Software
- </button>
- </div>
- <div id="area-software">
- @if (Model != null)
- {
- foreach (var software in Model)
- {
- @Html.Partial("_SoftwareEquipamento", software);
- }
- }
- </div>
- <script src="~/Scripts/jquery-1.8.0.min.js"></script>
- <script src="~/Scripts/jquery.validate.min.js"></script>
- <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function(){
- $("#adicionar-novo-software").click(function () {
- $.get('/Equipamento/NovoSoftwareEquipamento', function (template) {
- $("#area-software").append(template);
- });
- });
- });
- </script>
- @model TesteCadastroAtivo.Models.tblEquipamentoSoftware
- @using (Html.BeginCollectionItem("tblEquipamentoSoftware"))
- {
- <div class="form-group">
- @Html.HiddenFor(model => model.eqsIdEquipamento)
- @Html.HiddenFor(model => model.eqsIdSoftware)
- <div class="form-group">
- @Html.LabelFor(model => model.eqsTipo, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.eqsTipo, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.eqsTipo, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="col-md-1">
- <a class="btn red" onclick="$(this).parent().parent().remove();">Excluir</a>
- </div>
- </div>
- }
- <div class="form-group">
- @Html.LabelFor(model => model.eqsIdSoftware, "eqsIdSoftware", htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.DropDownList("eqsIdSoftware", null, htmlAttributes: new { @class = "form-control" })
- @Html.ValidationMessageFor(model => model.eqsIdSoftware, "", new { @class = "text-danger" })
- </div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement