public ActionResult PagoOk() { carro = Session["carro"] as List <Carrito>; Cliente cli = new Cliente(); cli = Session["Usuario"] as Cliente; int total = 0; int idBoleta = 0; //Boleta bol = new Boleta(); foreach (var x in carro) { total += (x.PrecioUnitario * x.Cantidad); } using (barCodePruebaEntities Context = new barCodePruebaEntities()) { //Context.Proveedores.Add(entity); //Context.SaveChanges(); Boleta bol = new Boleta(); bol.IdCliente = cli.IdCliente; bol.Total = total; bol.Fecha = DateTime.Now.ToString("dd-MM-yyyy"); bol.estado = 1; bol.cuentaPago = int.Parse(Session["NCuenta"].ToString()); Context.Boleta.Add(bol); Context.SaveChanges(); idBoleta = bol.IdBoleta; } foreach (var x in carro) { Producto pro = new Producto(); pro = db.Producto.Where(i => i.IdProducto == x.IdProducto).FirstOrDefault(); pro.Stock = pro.Stock - x.Cantidad; db.SaveChanges(); Detalle det = new Detalle(); det.idDetalle = idBoleta; det.Cantidad = x.Cantidad; det.Total = (x.PrecioUnitario * x.Cantidad); det.IdProducto = x.IdProducto; db.Detalle.Add(det); db.SaveChanges(); } Session["carro"] = null; Session["NCuenta"] = null; return(View()); }