public static bool Eliminar(ProductoFactura productoFactura) { using (var db = new Repositorio <ProductoFactura>()) { if (db.Eliminar(productoFactura)) { return(true); } return(false); } }
public static bool Modificar(ProductoFactura productoFactura) { using (var db = new Repositorio <ProductoFactura>()) { if ((productoFacturaReturned = db.Modificar(productoFactura)) != null) { return(true); } return(false); } }
public static bool Buscar(Expression <Func <ProductoFactura, bool> > criterio, bool relaciones) { using (var db = new Repositorio <ProductoFactura>()) { if ((productoFacturaReturned = db.Buscar(criterio)) != null) { FacturasBLL.Buscar(x => x.FacturaId == productoFacturaReturned.FacturaId, true); productoFacturaReturned.Factura = FacturasBLL.facturaReturned; ProductosBLL.Buscar(x => x.ProductoId == productoFacturaReturned.ProductoId, true); productoFacturaReturned.Producto = ProductosFacturasBLL.productoFacturaReturned.Producto; return(true); } return(false); } }
public async Task <IActionResult> FinalizaCompraAsync(int id) { List <Item> cart = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart"); List <Producto> productos = new List <Producto>(); var client = await _context.Clients .FirstOrDefaultAsync(m => m.ID == id); if (cart.Count == 0) { //Inicializar insertando un dato a la tabla Factura con su respectivo ClientID Factura facturaOb = new Factura { Client = client, FechaDeCompra = DateTime.Now, Total = totalAPagar }; _context.Add(facturaOb); await _context.SaveChangesAsync(); //Inserto en la tabla N:M ProductoFactura ProductoFactura productoFactura; foreach (var item in cart) { productoFactura = new ProductoFactura { ProductoID = item.Products.ProductoID, Cantidad = item.Quantity, FacturaID = facturaOb.FacturaID }; _context.Add(productoFactura); await _context.SaveChangesAsync(); } //Reinicio el carrito de compras cart = new List <Item>(); SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart); //_context.Add(factura); //await _context.SaveChangesAsync(); return(RedirectToAction("Gracias/" + facturaOb.FacturaID)); } else { return(View("../Home/Index")); } //SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart); //return RedirectToAction("Index"); }
public ActionResult AgregarProducto(ProductoFactura productoFactura) { var productoId = int.Parse(Request["Id"]); if (productoId == 0) { ViewBag.ProductoId = new SelectList(db.Productos.ToList(), "Id", "Descripcion"); return(View(productoFactura)); } //var cantidad = int.Parse(Request["Cantidad"]); var producto = db.Productos.Find(productoId); var facturaView = (FacturaView)Session["facturaView"]; productoFactura = facturaView.Productos.Find(p => p.Id == productoId); if (productoFactura == null) { productoFactura = new ProductoFactura { Id = producto.Id, Descripcion = producto.Descripcion, Precio = int.Parse(Request["Precio"]), Cantidad = int.Parse(Request["Cantidad"]), CategoriaId = producto.CategoriaId, Disponible = producto.Disponible }; facturaView.Productos.Add(productoFactura); } else { productoFactura.Cantidad += int.Parse(Request["Cantidad"]); } ViewBag.Cliente = new SelectList(db.Clientes.ToList(), "Id", "Nombre"); return(View("NuevaFactura", facturaView)); }