You are on page 1of 3

1.- crear App web ASP.

net Framework > patron MVC


2.- En Model crear clase: Venta.cs
------------------clase: Venta.cs-----------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebAppPOO_01.Models
{
public class Venta
{//atributos
public string _numero { get; set; }
public DateTime _fecha { get; set; }
public string _cliente { get; set; }
public string _mueble { get; set; }
public double _precio { get; set; }
Venta públi
_numero = "";
_fecha = DateTime.Today;
_cliente = string.Empty;
_mueble = string.Empty;
_precio = 0;
}
//métodos descuento

if
0.02 * _precio;
else return 0.05 * _precio;
}
//método para el neto
public double Neto()
{
return _precio - Descuento();

}
-----------------------------------------------------------en la carpeta controller
crear un controlador en blanco llamado VentasController
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebAppPOO_01.Models;
namespace WebAppPOO_01.Controllers
{
public class VentasController : Controller
{
// GET: Ventas
public ActionResult ActionVenta()
{
return View(new Venta());
}
//POST
[HttpPost] public ActionResult ActionVenta(Venta reg)
{
ViewBag.descuento = reg.Descuento();
ViewBag.neto=reg.Neto();
return View(reg);
//ViewBag.Nombre="Daniel ";
//en la vista en el html
//<p> Hola ,@ViewBag.Nombre </p>

}
}
}

------------------------------------------------------------
Crear Vista Basado en Controlador ActionVenta()
------------------------------------------
@model WebAppPOO_01.Models.Venta

@{
ViewBag.Title = "ActionVenta";
}

<h2>Registro de Ventas</h2>

@using (Html.BeginForm()) //crea formulario html


{
<div class="form-horizontal">
<div class="form-group">
@Html.Label("Numero", htmlAttributes: new { @class = "control-label
col-md-2" })
@Html.TextBoxFor(model => model._numero, htmlAttributes: new { @class =
"form-control col-md-10" })
</div>
<div class=" form-group">
@Html.Label("Fecha", htmlAttributes: new { @class = "control-label col-
md-2" })
@Html.TextBoxFor(model => model._fecha, "{0:dd/MM/yyyy}",
htmlAttributes: new { @class = "form-control col-md-10" })

</div>
<div class=" form-group">
@Html.Label("Cliente", htmlAttributes: new { @class = "control-label
col-md-2" })
@Html.TextBoxFor(model => model._cliente, htmlAttributes: new { @class
= "form-control col-md-10" })

</div>
<div class=" form-group">
@Html.Label("Mueble", htmlAttributes: new { @class = "control-label
col-md-2" })
@Html.TextBoxFor(model => model._mueble, htmlAttributes: new { @class =
"form-control col-md-10" })

</div>
<div class=" form-group">
@Html.Label("Precio", htmlAttributes: new { @class = "control-label
col-md-2" })
@Html.TextBox("_precio", 0, htmlAttributes: new { @class = "form-
control col-md-10" })

</div>
<div class=" form-group">
@Html.Label("Descuento", htmlAttributes: new { @class = "control-label
col-md-2" })
@Html.TextBox("descuento", @ViewBag.descuento as String,
htmlAttributes: new { @class = "form-control col-md-10" })

</div>

<div class=" form-group">


@Html.Label("Neto", htmlAttributes: new { @class = "control-label col-
md-2" })
@Html.TextBox("neto", @ViewBag.neto as String, htmlAttributes: new
{ @class = "form-control col-md-10" })

</div>

<div class=" form-group">


@Html.ActionLink("Nuevo", "ActionVenta", null, new { @class = "btn btn-
default" })
<input type="submit" value="Procesar" class="btn btn-default" />

</div>

</div>

You might also like