I am running a billing system in ASP .Net MVC with 3 layers. I just need to record the detail of the sale, because the sale already inserts me. In the case of the detail I extract all the fields that are required to insert the detail, except the sales code that is self-generated (Example: 'V001').
That's why I want to do select top (1) * from VENTAS
and extract the 'V' and zeros (0) to add 1. Then it would be V001 > --- 1 (+1) > V002.
Could something like that be done or will there be conflict?
[HttpPost]
public ActionResult GuardarVenta(string RUC,double VEN_TOT,List<VentadetaEntity>ListadoDetalles)
{
VentaEntity x = new VentaEntity();
x.RUC = RUC.Trim();
x.VEN_TOT = VEN_TOT;
ViewBag.mensaje = venta.agregarVentaBL(x);
VentaEntity a = venta.ultimaVentaBL();
//a.VEN_COD;
//VentadetaEntity y = new VentadetaEntity();
//y.VEN_COD = "V003";
foreach (var item in ListadoDetalles)
{
VentadetaEntity d = new VentadetaEntity();
d.VEN_COD = a.VEN_COD;
//d.VEN_COD = "V003";
d.PROD_COD = int.Parse(item.PROD_COD.ToString());
d.DET_CANT = int.Parse(item.DET_CANT.ToString());
d.DET_PRE = double.Parse(item.DET_PRE.ToString());
ViewBag.mensaje = venta.agregarVentadetaBL(d);
//VentadetaEntity d = new VentadetaEntity("V003",PROD_COD,DET_CANT,DET_PRE);
}
//y.PROD_COD = int.Parse(PROD_COD);
//y.DET_CANT = DET_CANT;
//y.DET_PRE = DET_PRE;
//ViewBag.mensaje = venta.agregarVentadetaBL(y);
return Json(true);
//return RedirectToAction("ListarCliente");
}
Data Layer:
Currently, when I give it to save, I get the error that can not find data, why?