public static int EliminarInventario(int idInventario) { try { InventarioBLL.Delete(idInventario); Inventario objInventario = InventarioBLL.SelectById(idInventario); string tipo = objInventario.Tipo; List <DetalleInventario> listDetalle = DetalleInventarioBLL.SelectByInventario(idInventario); foreach (DetalleInventario detalle in listDetalle) { Producto objProducto = ProductoBLL.SelectById(detalle.IdProducto); int stock = objProducto.Stock; int cant = detalle.Cantidad; if (tipo == "Ingreso") { stock = stock - cant; } else { stock = stock + cant; } ProductoBLL.UpdateStock(Convert.ToString(objProducto.IdProducto), stock); } return(idInventario); } catch (Exception) { return(-1); } }
public static DetalleInventario InsertarDetalle(string idProducto, string cantidad, string idInventario, string tipo) { DetalleInventario objDetalleInventario = DetalleInventarioBLL.InsertWithReturn(idProducto, cantidad, idInventario); Producto objProducto = ProductoBLL.SelectById(Convert.ToInt32(idProducto)); int stock = objProducto.Stock; if (tipo == "Ingreso") { stock = stock + Convert.ToInt32(cantidad); } else { stock = stock - Convert.ToInt32(cantidad); } ProductoBLL.UpdateStock(idProducto, stock); return(objDetalleInventario); }