Upload
others
View
0
Download
0
Embed Size (px)
Citation preview
Facultad de Estadística e Informática
BASES DE DATOS AVANZADAS
Clase 22 MODEL VIEW CONTROLLER
Referencias Microsoft Virtual Academy. (9 agosto de 2014). Introduction to ASP.NET MVC. Obtenido de: https://mva.microsoft.com/en-US/training-courses/introduction-to-asp-net-mvc-8322?l=nKZwZ8Zy_3504984382
Rick Anderson. (28 sep de 2015). Getting Started with ASP.NET MVC 5. Obtenido de https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/getting-started
Nemanja, Kojic. ASP.NET MVC 5. Introducing ASP.NET MVC5. Microsoft. Obtenido de http://rti.etf.bg.ac.rs/rti/si3iep/vezbe-2014/ASP%20.NET%20MVC.pdf
Proyecto Final SISTEMA DISTRIBUIDO DE REGISTRO DE BOLETOS DE AUTOBUSES DE TRANSPORTE
Agregando las Vistas
Modelo
Vista Controlador
Crear la siguiente estructura de carpetas, en caso de no tenerla
Shared/_Layout.cshtml <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>@ViewBag.Title - Universidad Veracruzana</title> @Styles.Render("~/Content/css") @Scripts.Render("~/bundles/modernizr") </head> <body> <div class="navbar navbar-inverse navbar-fixed-top"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> @Html.ActionLink((string)ViewBag.Region, "Index", "Home", null, new { @class = "navbar-brand" }) </div> <div class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li>@Html.ActionLink("Inicio", "Index", "Home")</li> <li>@Html.ActionLink("Estados", "Index", "Estados")</li> <li>@Html.ActionLink("Pasajeros", "Index", "Pasajeros")</li> <li>@Html.ActionLink("Corridas", "Index", "Corridas")</li> <li>@Html.ActionLink("Boletos", "Index", "Boletos")</li> <li>@Html.ActionLink("Cambio de región", "Index", "Region")</li> </ul> </div> </div> </div> <div class="container body-content"> @RenderBody() <hr /> <footer> <p>© @DateTime.Now.Year - Universidad Veracruzana</p> </footer> </div> @Scripts.Render("~/bundles/jquery") @Scripts.Render("~/bundles/jqueryval") @Scripts.Render("~/bundles/bootstrap") @RenderSection("scripts", required: false) </body> </html>
Crear las vistas dentro de las carpetas indicadas
Boletos/_PartialCorridas.cshtml @model IEnumerable<ProyectoADO.ViewModels.CorridaViewModel> <p class="text-primary">Mostrando @Model.Count() elementos</p> @if (Model.Count() > 0) { <div class="table-responsive"> <table class="table table-bordered table-striped"> <thead> <tr> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().CorridaId) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Origen) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Destino) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Fecha) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Precio) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Asientos) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().AsientosDisponibles) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Origen.Region.Nombre) </th> <th></th> </tr> </thead> <tbody> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.CorridaId) </td> <td> @Html.DisplayFor(modelItem => item.Origen.Nombre) </td> <td> @Html.DisplayFor(modelItem => item.Destino.Nombre) </td> <td> @Html.DisplayFor(modelItem => item.Fecha) </td> <td> @Html.DisplayFor(modelItem => item.Precio) </td> <td> @Html.DisplayFor(modelItem => item.Asientos) </td> <td> @Html.DisplayFor(modelItem => item.AsientosDisponibles) </td> <td> @Html.DisplayFor(modelItem => item.Origen.Region.Nombre) </td> <td> <a href="@Url.Action("Comprar","Boletos", new { id = item.CorridaId })" title="Comprar" class="btn btn-link btn-xs">Comprar</a> </td> </tr> } </tbody> </table> </div> } else { <div class="alert alert-warning" role="alert"> No se han encontrado resultados. </div> }
Boletos/Eliminar.cshtml @model ProyectoADO.Models.Viaje @{ ViewBag.Title = "Boletos"; ViewBag.Message = "Eliminación"; } <h2>@ViewBag.Title <small>@ViewBag.Message</small></h2> @if (!ViewBag.esEliminable) { <p class="text-danger">Hay otros elementos relacionados con este elemento, por lo que no puede ser eliminado.</p> } else { <p class="text-danger">¿Está seguro que desea eliminar este elemento?</p> } @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="text-right"> @if (ViewBag.esEliminable) { <button type="submit" class="btn btn-danger">Eliminar</button> } <a href="@Url.Action("Index")" class="btn btn-default">Cancelar</a> </div> <div class="container-fluid"> <div class="form-group"> @Html.LabelFor(model => model.Corrida.OrigenId, new { @class = "control-label" })<br /> @Html.DisplayFor(model => model.Corrida.Origen.Nombre) </div> <div class="form-group"> @Html.LabelFor(model => model.Corrida.DestinoId, new { @class = "control-label" })<br /> @Html.DisplayFor(model => model.Corrida.Destino.Nombre) </div> <div class="form-group"> @Html.LabelFor(model => model.Corrida.Fecha, new { @class = "control-label" })<br /> @Html.DisplayFor(model => model.Corrida.Fecha) </div> <div class="form-group form-select"> @Html.LabelFor(model => model.Pasajero, new { @class = "control-label" })<br /> @Html.DisplayFor(model => model.Pasajero.Nombre) </div> <div class="form-group form-select"> @Html.LabelFor(model => model.NumAsiento, new { @class = "control-label" })<br /> @Html.DisplayFor(model => model.NumAsiento) </div> </div> }
Boletos/Index.cshtml @model IEnumerable<ProyectoADO.Models.Viaje> @{ ViewBag.Title = "Boletos"; ViewBag.Message = "Vendidos"; } <h2>@ViewBag.Title</h2> <p class="text-right"> <a href="@Url.Action("Index", "ConsultaBoletos")" class="btn btn-primary">Busca boletos</a> </p> <p class="text-primary">Mostrando @Model.Count() elementos</p> <div class="table-responsive"> <table class="table table-bordered table-striped"> <thead> <tr> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().ViajeId) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().CorridaId) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Corrida.Origen) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Corrida.Destino) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Corrida.Fecha) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Corrida.Precio) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Pasajero.Nombre) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().NumAsiento) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Corrida.Origen.Region.Nombre) </th> <th></th> </tr> </thead> <tbody> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.ViajeId) </td> <td> @Html.DisplayFor(modelItem => item.CorridaId) </td> <td> @Html.DisplayFor(modelItem => item.Corrida.Origen.Nombre) </td> <td> @Html.DisplayFor(modelItem => item.Corrida.Destino.Nombre) </td> <td> @Html.DisplayFor(modelItem => item.Corrida.Fecha) </td> <td> @Html.DisplayFor(modelItem => item.Corrida.Precio) </td> <td> @Html.DisplayFor(modelItem => item.Pasajero.Nombre) </td> <td> @Html.DisplayFor(modelItem => item.NumAsiento) </td> <td> @Html.DisplayFor(modelItem => item.Corrida.Origen.Region.Nombre) </td> <td> <a href="@Url.Action("Eliminar", new { id = item.ViajeId })" title="Eliminar" class="btn btn-link btn-xs">Cancelar</a> </td> </tr> } </tbody> </table> </div>
Boletos/Nuevo.cshtml @model ProyectoADO.Models.Viaje @{ ViewBag.Title = "Boletos"; ViewBag.Message = "Nuevo"; } <h2>@ViewBag.Title <small>@ViewBag.Message</small></h2> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="text-right"> <button type="submit" class="btn btn-primary">Guardar</button> <a href="@Url.Action("Index", "ConsultaBoletos")" class="btn btn-default">Cancelar</a> </div> <div class="container-fluid"> @Html.ValidationSummary(true, "", new { @class = "help-block" }) <div class="form-group"> @Html.LabelFor(model => model.Corrida.OrigenId, new { @class = "control-label" })<br /> @Html.DisplayFor(model => model.Corrida.Origen.Nombre) </div> <div class="form-group"> @Html.LabelFor(model => model.Corrida.DestinoId, new { @class = "control-label" })<br /> @Html.DisplayFor(model => model.Corrida.Destino.Nombre) </div> <div class="form-group"> @Html.LabelFor(model => model.Corrida.Fecha, new { @class = "control-label" })<br /> @Html.DisplayFor(model => model.Corrida.Fecha) </div> <div class="form-group form-select"> @Html.LabelFor(model => model.PasajeroId, new { @class = "control-label" }) @Html.DropDownListFor(model => model.PasajeroId, (SelectList)ViewBag.pasajeros, "Selecione un valor para este campo", htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.PasajeroId, "", new { @class = "text-danger" }) </div> <div class="form-group form-select"> @Html.LabelFor(model => model.NumAsiento, new { @class = "control-label" }) @Html.DropDownListFor(model => model.NumAsiento, (SelectList)ViewBag.asientosdisponibles, "Selecione un valor para este campo", htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.NumAsiento, "", new { @class = "text-danger" }) </div> </div> }
ConsultaBoletos/_PartialCorridas.cshtml @model IEnumerable<ProyectoADO.ViewModels.CorridaViewModel> <p class="text-primary">Mostrando @Model.Count() elementos</p> @if (Model.Count() > 0) { <div class="table-responsive"> <table class="table table-bordered table-striped"> <thead> <tr> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().CorridaId) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Origen) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Destino) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Fecha) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Precio) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Asientos) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().AsientosDisponibles) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Origen.Region.Nombre) </th> <th></th> </tr> </thead> <tbody> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.CorridaId) </td> <td> @Html.DisplayFor(modelItem => item.Origen.Nombre) </td> <td> @Html.DisplayFor(modelItem => item.Destino.Nombre) </td> <td> @Html.DisplayFor(modelItem => item.Fecha) </td> <td> @Html.DisplayFor(modelItem => item.Precio) </td> <td> @Html.DisplayFor(modelItem => item.Asientos) </td> <td> @Html.DisplayFor(modelItem => item.AsientosDisponibles) </td> <td> @Html.DisplayFor(modelItem => item.Origen.Region.Nombre) </td> <td> @if (item.AsientosDisponibles > 0) { <a href="@Url.Action("Nuevo", "Boletos", new { CorridaId = item.CorridaId })" title="Comprar" class="btn btn-link btn-xs">Comprar</a> } else { <div class="badge">No disponibles</div> } </td> </tr> } </tbody> </table> </div> } else { <div class="alert alert-warning" role="alert"> No se han encontrado resultados. </div> }
ConsultaBoletos/Index.cshtml @model ProyectoADO.ViewModels.ConsultaBoletosViewModel @{ ViewBag.Title = "Consulta Boletos"; } <h2>@ViewBag.Title</h2> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="container-fluid"> @Html.ValidationSummary(true, "", new { @class = "help-block" }) <div class="row"> <div class="col-md-3"> <div class="well well-sm"> <div class="form-group form-select"> @Html.LabelFor(model => model.OrigenId, new { @class = "control-label" }) @Html.DropDownListFor(model => model.OrigenId, (SelectList)ViewBag.estados, "Selecione un estado", htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.OrigenId, "", new { @class = "text-danger" }) </div> <div class="form-group form-select"> @Html.LabelFor(model => model.DestinoId, new { @class = "control-label" }) @Html.DropDownListFor(model => model.DestinoId, (SelectList)ViewBag.estados, "Selecione un estado", htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.DestinoId, "", new { @class = "text-danger" }) </div> <div class="form-group"> @Html.LabelFor(model => model.Fecha, new { @class = "control-label" }) @Html.EditorFor(model => model.Fecha, new { htmlAttributes = new { placeholder = "Introduzca un valor para este campo", @class = "form-control", type = "datetime-local", data_val_date = "El campo debe ser una fecha válida" } }) @Html.ValidationMessageFor(model => model.Fecha, "", new { @class = "text-danger" }) </div> <div class="form-group"> <button type="submit" class="btn btn-primary">Buscar boletos</button> </div> </div> </div> <div class="col-md-9"> @if (Model != null) { @Html.Partial("_PartialCorridas", Model.Corridas) } </div> </div> </div> }
Corridas/Editar.cshtml @model ProyectoADO.Models.Corrida @{ ViewBag.Title = "Corridas"; ViewBag.Message = "Edición"; } <h2>@ViewBag.Title <small>@ViewBag.Message</small></h2> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="text-right"> <button type="submit" class="btn btn-primary">Guardar</button> <a href="@Url.Action("Index")" class="btn btn-default">Cancelar</a> </div> <div class="container-fluid"> @Html.ValidationSummary(true, "", new { @class = "help-block" }) <div class="form-group form-select"> @Html.LabelFor(model => model.OrigenId, new { @class = "control-label" }) @Html.DropDownListFor(model => model.OrigenId, (SelectList)ViewBag.estadoslocal, "Selecione un estado", htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.OrigenId, "", new { @class = "text-danger" }) </div> <div class="form-group form-select"> @Html.LabelFor(model => model.DestinoId, new { @class = "control-label" }) @Html.DropDownListFor(model => model.DestinoId, (SelectList)ViewBag.estados, "Selecione un estado", htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.DestinoId, "", new { @class = "text-danger" }) </div> <div class="form-group"> @Html.LabelFor(model => model.Fecha, new { @class = "control-label" }) @Html.EditorFor(model => model.Fecha, new { htmlAttributes = new { placeholder = "Introduzca un valor para este campo", @class = "form-control", type = "datetime-local", data_val_date = "El campo debe ser una fecha válida" } }) @Html.ValidationMessageFor(model => model.Fecha, "", new { @class = "text-danger" }) </div> <div class="form-group"> @Html.LabelFor(model => model.Precio, new { @class = "control-label" }) @Html.EditorFor(model => model.Precio, new { htmlAttributes = new { placeholder = "Introduzca un valor para este campo", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Precio, "", new { @class = "text-danger" }) </div> <div class="form-group"> @Html.LabelFor(model => model.Asientos, new { @class = "control-label" }) @Html.EditorFor(model => model.Asientos, new { htmlAttributes = new { placeholder = "Introduzca un valor para este campo", @class = "form-control", type = "number", min = "1", max = "50" } }) @Html.ValidationMessageFor(model => model.Asientos, "", new { @class = "text-danger" }) </div> </div> }
Corridas/Eliminar.cshtml @model ProyectoADO.Models.Corrida @{ ViewBag.Title = "Corridas"; ViewBag.Message = "Eliminación"; } <h2>@ViewBag.Title <small>@ViewBag.Message</small></h2> @if (!ViewBag.esEliminable) { <p class="text-danger">Hay otros elementos relacionados con este elemento, por lo que no puede ser eliminado.</p> } else { <p class="text-danger">¿Está seguro que desea eliminar este elemento?</p> } @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="text-right"> @if (ViewBag.esEliminable) { <button type="submit" class="btn btn-danger">Eliminar</button> } <a href="@Url.Action("Index")" class="btn btn-default">Cancelar</a> </div> <div class="container-fluid"> <div class="form-group"> @Html.LabelFor(model => model.Origen, new { @class = "control-label" })<br /> @Html.DisplayFor(model => model.Origen.Nombre) </div> <div class="form-group"> @Html.LabelFor(model => model.Destino, new { @class = "control-label" })<br /> @Html.DisplayFor(model => model.Destino.Nombre) </div> <div class="form-group form-select"> @Html.LabelFor(model => model.Fecha, new { @class = "control-label" })<br /> @Html.DisplayFor(model => model.Fecha) </div> <div class="form-group form-select"> @Html.LabelFor(model => model.Precio, new { @class = "control-label" })<br /> @Html.DisplayFor(model => model.Precio) </div> <div class="form-group form-select"> @Html.LabelFor(model => model.Asientos, new { @class = "control-label" })<br /> @Html.DisplayFor(model => model.Asientos) </div> </div> }
Corridas/Index.cshtml
@model IEnumerable<ProyectoADO.ViewModels.CorridaViewModel> @{ ViewBag.Title = "Corridas"; } <h2>@ViewBag.Title</h2> <p class="text-right"> <a href="@Url.Action("Nuevo")" class="btn btn-primary">Nuevo Elemento</a> </p> <p class="text-primary">Mostrando @Model.Count() elementos</p> <div class="table-responsive"> <table class="table table-bordered table-striped"> <thead> <tr> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().CorridaId) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Origen) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Destino) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Fecha) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Precio) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Asientos) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().AsientosDisponibles) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Origen.Region.Nombre) </th> <th></th> </tr> </thead> <tbody> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.CorridaId) </td> <td> @Html.DisplayFor(modelItem => item.Origen.Nombre) </td> <td> @Html.DisplayFor(modelItem => item.Destino.Nombre) </td> <td> @Html.DisplayFor(modelItem => item.Fecha) </td> <td> @Html.DisplayFor(modelItem => item.Precio) </td> <td> @Html.DisplayFor(modelItem => item.Asientos) </td> <td> @Html.DisplayFor(modelItem => item.AsientosDisponibles) </td> <td> @Html.DisplayFor(modelItem => item.Origen.Region.Nombre) </td> <td> <a href="@Url.Action("Editar", new { id = item.CorridaId })" title="Editar" class="btn btn-link btn-xs">Editar</a> <a href="@Url.Action("Eliminar", new { id = item.CorridaId })" title="Eliminar" class="btn btn-link btn-xs">Eliminar</a> </td> </tr> } </tbody> </table> </div>
Corridas/Nuevo.cshtml @model ProyectoADO.Models.Corrida @{ ViewBag.Title = "Corridas"; ViewBag.Message = "Nuevo"; } <h2>@ViewBag.Title <small>@ViewBag.Message</small></h2> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="text-right"> <button type="submit" class="btn btn-primary">Guardar</button> <a href="@Url.Action("Index")" class="btn btn-default">Cancelar</a> </div> <div class="container-fluid"> @Html.ValidationSummary(true, "", new { @class = "help-block" }) <div class="form-group form-select"> @Html.LabelFor(model => model.OrigenId, new { @class = "control-label" }) @Html.DropDownListFor(model => model.OrigenId, (SelectList)ViewBag.estadoslocal, "Selecione un estado", htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.OrigenId, "", new { @class = "text-danger" }) </div> <div class="form-group form-select"> @Html.LabelFor(model => model.DestinoId, new { @class = "control-label" }) @Html.DropDownListFor(model => model.DestinoId, (SelectList)ViewBag.estados, "Selecione un estado", htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.DestinoId, "", new { @class = "text-danger" }) </div> <div class="form-group"> @Html.LabelFor(model => model.Fecha, new { @class = "control-label" }) @Html.EditorFor(model => model.Fecha, new { htmlAttributes = new { placeholder = "Introduzca un valor para este campo", @class = "form-control", type = "datetime-local“, data_val_date = "El campo debe ser una fecha válida" } }) @Html.ValidationMessageFor(model => model.Fecha, "", new { @class = "text-danger" }) </div> <div class="form-group"> @Html.LabelFor(model => model.Precio, new { @class = "control-label" }) @Html.EditorFor(model => model.Precio, new { htmlAttributes = new { placeholder = "Introduzca un valor para este campo", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Precio, "", new { @class = "text-danger" }) </div> <div class="form-group"> @Html.LabelFor(model => model.Asientos, new { @class = "control-label" }) @Html.EditorFor(model => model.Asientos, new { htmlAttributes = new { placeholder = "Introduzca un valor para este campo", @class = "form-control", type = "number", min = "1", max = "50" } }) @Html.ValidationMessageFor(model => model.Asientos, "", new { @class = "text-danger" }) </div> </div> }
Estados/Index.cshtml
@model IEnumerable<ProyectoADO.Models.Estado> @{ ViewBag.Title = "Estados"; } <h2>@ViewBag.Title</h2> <p class="text-primary">Mostrando @Model.Count() elementos</p> <div class="table-responsive"> <table class="table table-bordered table-striped"> <thead> <tr> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().EstadoId) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Nombre) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().NombreAbreviado) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Region.Nombre) </th> </tr> </thead> <tbody> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.EstadoId) </td> <td> @Html.DisplayFor(modelItem => item.Nombre) </td> <td> @Html.DisplayFor(modelItem => item.NombreAbreviado) </td> <td> @Html.DisplayFor(modelItem => item.Region.Nombre) </td> </tr> } </tbody> </table> </div>
Home/Index.cshtml @{ ViewBag.Title = "Home Page"; } <div class="jumbotron"> <h1>Universidad Veracruzana</h1> <p class="lead">Este es un ejemplo de lo mímino requerido como proyecto final.</p> <p><a href="https://www.uv.mx/personal/ermeneses/" class="btn btn-primary btn-lg">Más información »</a></p> </div> <div class="row"> <div class="col-md-3"> <h2>Estados</h2> <p> Catálogo de estados. </p> <p><a class="btn btn-default" href="@Url.Action("Index", "Estados")">Estados »</a></p> </div> <div class="col-md-3"> <h2>Pasajeros</h2> <p> Catálogo de pasajeros. </p> <p><a class="btn btn-default" href="@Url.Action("Index", "Pasajeros")">Pasajeros »</a></p> </div> <div class="col-md-3"> <h2>Corridas</h2> <p> Catálogo de corridas. </p> <p><a class="btn btn-default" href="@Url.Action("Index", "Corridas")">Corridas »</a></p> </div> <div class="col-md-3"> <h2>Boletos</h2> <p> Catálogo de boletos. </p> <p><a class="btn btn-default" href="@Url.Action("Index", "Boletos")">Boletos »</a></p> </div> </div>
Pasajeros/Editar.cshtml @model ProyectoADO.Models.Pasajero @{ ViewBag.Title = "Pasajeros"; ViewBag.Message = "Edición"; } <h2>@ViewBag.Title <small>@ViewBag.Message</small></h2> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="text-right"> <button type="submit" class="btn btn-primary">Guardar</button> <a href="@Url.Action("Index")" class="btn btn-default">Cancelar</a> </div> <div class="container-fluid"> @Html.ValidationSummary(true, "", new { @class = "help-block" }) <div class="form-group"> @Html.LabelFor(model => model.Nombre, new { @class = "control-label" }) @Html.EditorFor(model => model.Nombre, new { htmlAttributes = new { placeholder = "Introduzca un valor para este campo", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Nombre, "", new { @class = "text-danger" }) </div> <div class="form-group"> @Html.LabelFor(model => model.Correo, new { @class = "control-label" }) @Html.EditorFor(model => model.Correo, new { htmlAttributes = new { placeholder = "Introduzca un valor para este campo", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Correo, "", new { @class = "text-danger" }) </div> <div class="form-group form-select"> @Html.LabelFor(model => model.EstadoId, new { @class = "control-label" }) @Html.DropDownListFor(model => model.EstadoId, (SelectList)ViewBag.estadoslocal, "Selecione un estado", htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.EstadoId, "", new { @class = "text-danger" }) </div> </div> }
Pasajeros/Eliminar.cshtml @model ProyectoADO.Models.Pasajero @{ ViewBag.Title = "Pasajeros"; ViewBag.Message = "Eliminación"; } <h2>@ViewBag.Title <small>@ViewBag.Message</small></h2> @if (!ViewBag.esEliminable) { <p class="text-danger">Hay otros elementos relacionados con este elemento, por lo que no puede ser eliminado.</p> } else { <p class="text-danger">¿Está seguro que desea eliminar este elemento?</p> } @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="text-right"> @if (ViewBag.esEliminable) { <button type="submit" class="btn btn-danger">Eliminar</button> } <a href="@Url.Action("Index")" class="btn btn-default">Cancelar</a> </div> <div class="container-fluid"> <div class="form-group"> @Html.LabelFor(model => model.Nombre, new { @class = "control-label" })<br /> @Html.DisplayFor(model => model.Nombre) </div> <div class="form-group"> @Html.LabelFor(model => model.Correo, new { @class = "control-label" })<br /> @Html.DisplayFor(model => model.Correo) </div> <div class="form-group form-select"> @Html.LabelFor(model => model.EstadoId, new { @class = "control-label" })<br /> @Html.DisplayFor(model => model.Estado.Nombre) </div> </div> }
Pasajeros/Index.cshtml @model IEnumerable<ProyectoADO.Models.Pasajero> @{ ViewBag.Title = "Pasajeros"; } <h2>@ViewBag.Title</h2> <p class="text-primary">Mostrando @Model.Count() elementos</p> <p class="text-right"> <a href="@Url.Action("Nuevo")" class="btn btn-primary">Nuevo Elemento</a> </p> <div class="table-responsive"> <table class="table table-bordered table-striped"> <thead> <tr> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().PasajeroId) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Nombre) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Correo) </th> <th> @Html.DisplayNameFor(model => model.FirstOrDefault().Estado.Nombre) </th> <th></th> </tr> </thead> <tbody> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.PasajeroId) </td> <td> @Html.DisplayFor(modelItem => item.Nombre) </td> <td> @Html.DisplayFor(modelItem => item.Correo) </td> <td> @Html.DisplayFor(modelItem => item.Estado.Nombre) </td> <td> <a href="@Url.Action("Editar", new { id = item.PasajeroId })" title="Editar" class="btn btn-link btn-xs">Editar</a> <a href="@Url.Action("Eliminar", new { id = item.PasajeroId })" title="Eliminar" class="btn btn-link btn-xs">Eliminar</a> </td> </tr> } </tbody> </table> </div>
Pasajeros/Nuevo.cshtml @model ProyectoADO.Models.Pasajero @{ ViewBag.Title = "Pasajeros"; ViewBag.Message = "Nuevo"; } <h2>@ViewBag.Title <small>@ViewBag.Message</small></h2> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="text-right"> <button type="submit" class="btn btn-primary">Guardar</button> <a href="@Url.Action("Index")" class="btn btn-default">Cancelar</a> </div> <div class="container-fluid"> @Html.ValidationSummary(true, "", new { @class = "help-block" }) <div class="form-group"> @Html.LabelFor(model => model.Nombre, new { @class = "control-label" }) @Html.EditorFor(model => model.Nombre, new { htmlAttributes = new { placeholder = "Introduzca un valor para este campo", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Nombre, "", new { @class = "text-danger" }) </div> <div class="form-group"> @Html.LabelFor(model => model.Correo, new { @class = "control-label" }) @Html.EditorFor(model => model.Correo, new { htmlAttributes = new { placeholder = "Introduzca un valor para este campo", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Correo, "", new { @class = "text-danger" }) </div> <div class="form-group form-select"> @Html.LabelFor(model => model.EstadoId, new { @class = "control-label" }) @Html.DropDownListFor(model => model.EstadoId, (SelectList)ViewBag.estadoslocal, "Selecione un estado", htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.EstadoId, "", new { @class = "text-danger" }) </div> </div> }
Region/Index.cshtml
@model ProyectoADO.ViewModels.RegionViewModel @{ ViewBag.Title = "Seleccione su región"; } <h2>@ViewBag.Title</h2> @using (Html.BeginForm()) { @Html.AntiForgeryToken() @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <div class="jumbotron"> <h1>Región</h1> <p class="lead">Seleccione la región donde se encuentra.</p> <p> <div class="form-group form-select"> @Html.DropDownListFor(model => model.FragmentoId, (SelectList)ViewBag.fragmentos, "Selecione una región", htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.FragmentoId, "", new { @class = "text-danger" }) </div> </p> <p><button id="btnGuardar" class="btn btn-primary" type="submit">Iniciar »</button></p> </div> }
Qué hemos realizado hasta ahora de Pasos previos:
Entity Framework Inserción de conexiones a base de datos distribuida Ayuda para el manejo de validaciones en español Clase Filtro para verificar que se ha seleccionado una
Región Usada en BaseController [VerificaRegion]
Qué hemos realizado hasta ahora
de Modelos
Region RegionLocal Estado Pasajero Corrida Viaje
Qué hemos realizado hasta ahora
de DbContext
CentroDbContext SurDbContext NorteDbContext
BaseDbContext
Qué hemos realizado hasta ahora de Migración de LOS MODELOS a la base de datos usando la consola
de administración de paquetes Enable-Migrations Habilita la migración creando la carpeta Migrations/Centro,
Migrations/Sur, Migrations/Norte. Se crea el Catálogo de datos distribuidos (DDC, Data Distributed
Catalog por sus siglas en inglés). Y se asignan valores de inicio.
Add-Migration – Crea las tablas de acuerdo a los contextos y Modelos otorgados Update-Database – Aplica las migraciones a la base de datos
Qué hemos realizado hasta ahora
de
ViewModels
RegionViewModel CorridaViewModel ConsultaBoletosViewModel
Usada en ViewsRegionIndex
Qué hemos realizado hasta ahora
de
Controladores
HomeController RegionController EstadosController PasajerosController CorridasController
ConsultaBoletosController
BoletosController
BaseController
Inicia con [VerificaRegion] Métodos como: ObtenCorrida ObtenAsientosDisponibles PopulateEstadosLocalDropDownList
Obtiene los Estados de la Región seleccionada
Inicio, donde es seleccionada la región
Administra los pasajeros
Administra las corridas
Consulta de todas las corridas con el origen, destino y la fecha seleccionada
Asigna un boleto, con una fecha y un asiento a un pasajero
Qué hemos realizado hasta ahora
de
Vistas
Boletos
_PartialCorridas
Eliminar
Index
Nuevo
ConsultaBoletos
_PartialCorridas
Index
Corridas
Editar
Eliminar
Index
Nuevo
Estado
Index
Home
Index
Pasajeros
Editar
Eliminar
Index
Nuevo
Region
Index
Shared/_Layout.cshtml
Ejecutar el proyecto
Verifique que existan estados por Región
Agregue lo siguiente 3 Pasajeros
Agregue lo siguiente 3 Corridas con la misma fecha, origen y destino pero distinta hora
2 Corridas con la misma fecha, origen y destino (distinta a la anterior) pero distinta hora
Realice consultas de boletos Realice consultas en los estados y fechas ingresadas
Comprar boletos Compre 2 boletos mismo horario para Ciudad de México - Puebla
Se han comprado 2 boletos
Verifique la Base de Datos Distribuida
Gracias por su atención