// GET: Cliente public ActionResult Index() { _base = new ProductoBL(); var _productos = _base.ObtenerTodos(); List <Producto> _result = (_productos).Cast <Producto>().ToList(); return(View(_result)); }
// GET: Facturacion public ActionResult Index() { _base = new FacturaBL(); _usuarioLogeado = (Usuario)Session["User"]; List <Factura> _result; if (_usuarioLogeado.Rol.FirstOrDefault().nombre == "SUPERADMIN") { var _facturas = _base.ObtenerTodos(); _result = (_facturas).Cast <Factura>().ToList(); return(View(_result)); } else { var _facturas = FacturaBL.ObtenerPorVendedor(_usuarioLogeado.id); _result = (_facturas).Cast <Factura>().ToList(); return(View(_result)); } }
public ActionResult CrearFactura(int?id, int?idFactura, int?idProducto) { int.TryParse(idFactura.ToString(), out int _idFactura); int.TryParse(id.ToString(), out int _idCliente); Factura _registro; if (id > 0) { var _usuarioLogeado = (Usuario)Session["User"]; _registro = new Factura(); _registro.idVendedor = _usuarioLogeado.id; _registro.idCliente = _idCliente; _registro.facturado = false; _registro.valorTotal = 0; _base = new FacturaBL(); _registro = (Factura)_base.Guardar(_registro); return(RedirectToAction("CrearFactura", "Facturacion", new { @id = 0, @idFactura = _registro.id })); } else if (_idFactura > 0) { //EXISTE FACTURA _base = new FacturaBL(); _registro = (Factura)_base.ObtenerId(_idFactura); _base = new ProductoBL(); var _productos = (_base.ObtenerTodos()).Cast <Producto>().ToList(); _registro.Productos = _productos; //SE VERIFICA SI SELECCIONARON PRODUCTOS NUEVOS int.TryParse(idProducto.ToString(), out int _idProducto); if (_idProducto > 0) { //SE CREA EL DETALLE EN LA FACTURA _base = new DetalleFacturaBL(); var _detalle = new DetalleFactura(); _detalle.cantidad = 1; _detalle.idFactura = _idFactura; _detalle.idProducto = _idProducto; _detalle.precio = _registro.Productos.Where(x => x.id == _idProducto).FirstOrDefault().precio; _base.Guardar(_detalle); double _valorTotal = 0; //SE ACTUALIZA LA FACTURA EL VALOR A PAGAR (MEJORABLE CON LAS SUMAS DE LOS DETALLES) Parallel.ForEach(_registro.DetalleFactura.Cast <DetalleFactura>(), currentElement => { _valorTotal += currentElement.precio; }); _registro.valorTotal = _valorTotal; _base = new FacturaBL(); _registro = (Factura)_base.Editar(_registro); _registro.Productos = _productos; } return(View(_registro)); } else { return(RedirectToAction("Index")); } }