public CambioVO create(DbConnection connection, DbTransaction transaction, CambioVO cambioVO) { try { DbCommand command = connection.CreateCommand(); if (transaction != null) { command.Transaction = transaction; } command.CommandText = "INSERT INTO Cambio (cod_Partido,cod_Jugador_Entra, cod_Jugador_Sale,minuto) " + "values (@cod_Partido,@cod_Jugador_Entra,@cod_Jugador_Sale,@minuto)"; DbParameter cod_PartidoParam = command.CreateParameter(); cod_PartidoParam.ParameterName = "@cod_Partido"; cod_PartidoParam.DbType = DbType.Int32; cod_PartidoParam.Value = cambioVO.Cd_Partido; cod_PartidoParam.Size = 32; command.Parameters.Add(cod_PartidoParam); DbParameter cod_Jugador_EntraParam = command.CreateParameter(); cod_Jugador_EntraParam.ParameterName = "@cod_Jugador_Entra"; cod_Jugador_EntraParam.DbType = DbType.Int32; cod_Jugador_EntraParam.Value = cambioVO.Cd_Jugador_Entra; cod_Jugador_EntraParam.Size = 32; command.Parameters.Add(cod_Jugador_EntraParam); DbParameter cod_Jugador_SaleParam = command.CreateParameter(); cod_Jugador_SaleParam.ParameterName = "@cod_Jugador_Sale"; cod_Jugador_SaleParam.DbType = DbType.Int32; cod_Jugador_SaleParam.Value = cambioVO.Cd_Jugador_Sale; cod_Jugador_SaleParam.Size = 32; command.Parameters.Add(cod_Jugador_SaleParam); DbParameter minutoParam = command.CreateParameter(); minutoParam.ParameterName = "@minuto"; minutoParam.DbType = DbType.Int32; minutoParam.Value = cambioVO.Minuto; minutoParam.Size = 32; command.Parameters.Add(minutoParam); command.Prepare(); int insertedRows = command.ExecuteNonQuery(); if (insertedRows == 0) { throw new SQLException("errorrrrrrr"); } ICambioIdentifierRetriever cambioIdentifierRetriever = CambioIdentifierRetrieverFactory.GetRetriever(); Int64 cambioIdentifier = cambioIdentifierRetriever.GetGeneratedIdentifier(connection, transaction); return(new CambioVO((int)cambioIdentifier, cambioVO.Cd_Partido, cambioVO.Cd_Jugador_Entra, cambioVO.Cd_Jugador_Sale, cambioVO.Minuto)); } catch (DbException e) { throw new InternalErrorException(e); } }
/*genera un PartidoTotalCO con todos los datos de un partido * tanto el PartidoVO como la lista de GolVOs y PartidoJugadoVOs * de los jugadores que participan en el * */ public PartidoTotalCO generarPartidoCompleto(int codCompeticion, String jornada, int codLocal, int codVisitante, bool saveChangesInBD = true) { PartidoVO partido = generarPartidoSimple(codCompeticion, jornada, codLocal, codVisitante, 1); var jugadoresLocal = generar11Titular(codLocal); var jugadoresVisitante = generar11Titular(codVisitante); var listaPartidosJugados = new List <PartidoJugadoVO>(); var golesLocal = new List <GolVO>(); var golesVisitante = new List <GolVO>(); //Se crean los partidosJugados para cada jugador del equipo local //titulares y suplentes int contador = 1; int numeroCambios = jugadoresLocal.Count - 11; foreach (var item in jugadoresLocal) { if (contador > 11) { listaPartidosJugados.Add(generarPartidoJugadoSimple(item.Cod_Jugador, "Suplente")); } else { listaPartidosJugados.Add(generarPartidoJugadoSimple(item.Cod_Jugador, "Titular")); } contador++; } //aqui se crean los cambios equipo local var cambiosLocal = new List <CambioVO>(); for (int i = 0; i < numeroCambios; i++) { var cambio = new CambioVO((jugadoresLocal[11 + i]).Cod_Jugador, (jugadoresLocal[1 + i]).Cod_Jugador, rand.Next(0, 90)); cambiosLocal.Add(cambio); } //Se crean los partidosJugados para cada jugador del equipo visitante //titulares y suplentes contador = 1; numeroCambios = jugadoresVisitante.Count - 11; foreach (var item in jugadoresVisitante) { if (contador > 11) { listaPartidosJugados.Add(generarPartidoJugadoSimple(item.Cod_Jugador, "Suplente")); } else { listaPartidosJugados.Add(generarPartidoJugadoSimple(item.Cod_Jugador, "Titular")); } contador++; } //aqui se crean los cambios equipo visitante var cambiosVisitante = new List <CambioVO>(); for (int i = 0; i < numeroCambios; i++) { var cambio = new CambioVO(((JugadorVO)jugadoresVisitante[11 + i]).Cod_Jugador, ((JugadorVO)jugadoresVisitante[1 + i]).Cod_Jugador, rand.Next(0, 90)); cambiosVisitante.Add(cambio); } //aqui generamos las tarjetas del equipo local var tarjetasLocal = new List <TarjetaVO>(); int numeroTarjetas = rand.Next(0, 6); for (int i = 0; i < numeroTarjetas; i++) { var tarjeta = new TarjetaVO(((JugadorVO)jugadoresLocal[i]).Cod_Jugador, rand.Next(0, 90), "Yellow", "Aggressive tackle"); tarjetasLocal.Add(tarjeta); } //aqui generamos las tarjetas del equipo visitante var tarjetasVisitante = new List <TarjetaVO>(); numeroTarjetas = rand.Next(0, 6); for (int i = 0; i < numeroTarjetas; i++) { var tarjeta = new TarjetaVO(((JugadorVO)jugadoresVisitante[i]).Cod_Jugador, rand.Next(0, 90), "Yellow", "Aggressive tackle"); tarjetasVisitante.Add(tarjeta); } //generamos ahora los goles concretos del partido var goleadoresLocal = generador.generaGoleadoresLista(jugadoresLocal, partido.Goles_Local); var goleadoresVisitante = generador.generaGoleadoresLista(jugadoresVisitante, partido.Goles_Visitante); foreach (JugadorVO item in goleadoresLocal) { golesLocal.Add(new GolVO(item.Cod_Jugador, generador.generarPosesion(), "Pie", "http://www.youtube.com/v/fV5UGc9nBAc&hl=en&fs=1")); } foreach (JugadorVO item in goleadoresVisitante) { golesVisitante.Add(new GolVO(item.Cod_Jugador, generador.generarPosesion(), "Cabeza", "http://www.youtube.com/v/fV5UGc9nBAc&hl=en&fs=1")); } cambiosLocal.AddRange(cambiosVisitante); golesLocal.AddRange(golesVisitante); tarjetasLocal.AddRange(tarjetasVisitante); PartidoTotalCO partidoCompleto = new PartidoTotalCO(partido, listaPartidosJugados, golesLocal, cambiosLocal, tarjetasLocal); if (saveChangesInBD) { PartidoTotalCO partidoTotal = fachada.pruebaCrearPartidoTotal(partidoCompleto); return(partidoTotal); } partidoCompleto.playersLocal = jugadoresLocal.Cast <JugadorVO>().ToList(); partidoCompleto.playersVisitor = jugadoresVisitante.Cast <JugadorVO>().ToList(); return(partidoCompleto); }