Documentos de Académico
Documentos de Profesional
Documentos de Cultura
DIRECCIÓN ACADÉMICA
CARRERAS PROFESIONALES
PROFESOR :
SEMESTRE : 2023 – 3
CICLO : Tercero
SECCION : GRUPO : 01
FECHA :
DURACION : 90 minutos
EVALUACIÓN SUSTITUTORIO
Definir una clase llamada Empleado, definida por los campos idempleado, nombre, dni, área y
sueldo.
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace POO1_QQJJ.Models
{
public class Empleado
{
[Display(Name = "ID DEL EMPLEADO")]
public int idEmpleado { get; set; }
[Display(Name = "NOMBRE")]
public string nombre { get; set; }
[Display(Name = "DNI")]
public string dni { get; set; }
[Display(Name = "AREA")]
public string area { get; set; }
[Display(Name = "SUELDO")]
public decimal sueldo { get; set; }
}
}
Pregunta 02
[HttpPost]
public ActionResult Create(Empleado empleado)
{
if (!ModelState.IsValid)
{
return View(empleado);
}
empleados.Add(empleado);
ViewBag.mensaje = "empleado registrado";
return View(empleado);
}
Programa el ActionResult Details, donde visualiza los datos del empleado seleccionado
almacenado en la colección
return View(empleado);
}
Pregunta 03
Se pide realizar la siguiente actividad:
Diseñar una vista para el enunciado.
LISTADO
@model IEnumerable<POO1_QQJJ.Models.Empleado>
@{
ViewBag.Title = "Listado";
}
<h2>LISTADO DE EMPLEADOS</h2>
<p>
@Html.ActionLink("AGREGAR EMPLEADO", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.idEmpleado)
</th>
<th>
@Html.DisplayNameFor(model => model.nombre)
</th>
<th>
@Html.DisplayNameFor(model => model.dni)
</th>
<th>
@Html.DisplayNameFor(model => model.area)
</th>
<th>
@Html.DisplayNameFor(model => model.sueldo)
</th>
<th></th>
</tr>
</table>
AGREGAR
@using POO1_QQJJ.Models
@model Empleado
@{
ViewBag.Title = "Create";
}
<h2>AGREGAR</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Empleado</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.idEmpleado, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.idEmpleado, new { htmlAttributes = new { @class = "form-control" }
})
@Html.ValidationMessageFor(model => model.idEmpleado, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.nombre, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.nombre, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.nombre, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.dni, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.dni, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.dni, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.area, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.area, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.area, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.sueldo, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.sueldo, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.sueldo, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
@Html.ActionLink("NUEVO", "AGREGAR", null, htmlAttributes: new { @class = "btn btn-primary" })
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@ViewBag.mensaje
</div>
<div>
@Html.ActionLink("Back to List", "lISTADO")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
LISTADO
DETALLES
@model POO1_QQJJ.Models.Empleado
@{
ViewBag.Title = "Details";
}
<h2>DETALLES</h2>
<div>
<h4>Empleado</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.idEmpleado)
</dt>
<dd>
@Html.DisplayFor(model => model.idEmpleado)
</dd>
<dt>
@Html.DisplayNameFor(model => model.nombre)
</dt>
<dd>
@Html.DisplayFor(model => model.nombre)
</dd>
<dt>
@Html.DisplayNameFor(model => model.dni)
</dt>
<dd>
@Html.DisplayFor(model => model.dni)
</dd>
<dt>
@Html.DisplayNameFor(model => model.area)
</dt>
<dd>
@Html.DisplayFor(model => model.area)
</dd>
<dt>
@Html.DisplayNameFor(model => model.sueldo)
</dt>
<dd>
@Html.DisplayFor(model => model.sueldo)
</dd>
</dl>
</div>
<p>
CONTROLADOR
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
using POO1_QQJJ.Models;
namespace POO1_QQJJ.Controllers
{
public class EmpleadoController : Controller
{
private List<Empleado> empleados = new List<Empleado>
{
new Empleado { idEmpleado = 1, nombre = "julio quispe", dni = "72655037", area = "Almacen", sueldo =
1200 }
};
// GET: Empleado
public ActionResult Listado()
{
return View(empleados);
}
public ActionResult Create()
{
return View(new Empleado());
}
[HttpPost]
public ActionResult Create(Empleado empleado)
{
if (!ModelState.IsValid)
{
return View(empleado);
}
empleados.Add(empleado);
ViewBag.mensaje = "empleado registrado";
return View(empleado);
}
public ActionResult Details(string dni )
{
Empleado empleado = empleados.SingleOrDefault(e =>
e.dni == dni);
return View(empleado);
}
}
}