private void btnGenerarFact_Click(object sender, EventArgs e) { FacturasView fact = new FacturasView(null); fact.Size = new Size(1300, 600); fact.ShowDialog(); }
public ActionResult ComprarProducto() { var facturaView = new FacturasView(); facturaView.Productos = new List <OrdenProductoView>(); Session["orderView"] = facturaView; return(View(facturaView)); }
public ActionResult ComprarProducto(FacturasView orderView) { orderView = Session["orderView"] as FacturasView; if (orderView.Productos.Count == 0) { ViewBag.Error = "Debe ingresar detalle"; return(View(orderView)); } var ubicacionId = db.Ubicaciones.ToList().Select(o => o.IdUbicacion).Max(); int orderID = 0; using (var transaction = db.Database.BeginTransaction()) { try { var order = new Facturas { NumeroFactura = "000", FechaCompra = DateTime.Now, FechaRegistro = DateTime.Now, UbicacionId = ubicacionId }; db.Facturas.Add(order); db.SaveChanges(); orderID = db.Facturas.ToList().Select(o => o.IdFactura).Max(); foreach (var item in orderView.Productos) { var orderDetail = new DetalleFactura { ProductoId = item.IdProducto, Total = item.Valor, PrecioCompra = item.Precio, FacturaId = orderID, Cantidad = Convert.ToInt32(item.Cantidad) }; db.DetalleFacturas.Add(orderDetail); db.SaveChanges(); } transaction.Commit(); } catch (Exception ex) { throw ex; } } return(RedirectToAction("Index")); }
private void btnGenerarFact_Click(object sender, EventArgs e) { FacturasView fact = new FacturasView(); fact.ShowDialog(); }