public void DisminuirSalud(int idPoketgotchi) { Pokegotchi pokegotchi = RecuperaPokegotchiPorId(idPoketgotchi); try { string sql = @"UPDATE Pokegotchi SET salud = @pSalud WHERE id = @pId"; SqlCommand cmd = new SqlCommand(sql, conexion.Conexion); cmd.Parameters.Add(CrearParametro("@pId", System.Data.SqlDbType.Int, 0, pokegotchi.Id)); cmd.Parameters.Add(CrearParametro("@pSalud", System.Data.SqlDbType.Int, 0, pokegotchi.Salud - new Random().Next(1, 3))); cmd.ExecuteNonQuery(); } catch (Exception error) { } }
public List <Pokegotchi> RecuperaPokegotchisPorIdUsuario(int idUsuario) { List <Pokegotchi> listaPokegotchi = new List <Pokegotchi>(); try { string sql = @"select p.idApi, l.felicidad, l.idPokemon, l.idUsuario, p.NombrePokemon, l.id, p.Tipo , l.salud from Pokemon p INNER JOIN Pokegotchi as l on p.id = l.idPokemon and idUsuario = @pIdUsuario"; SqlCommand cmd = new SqlCommand(sql, conexion.Conexion); SqlParameter pIdUsuario = new SqlParameter("@pIdUsuario", idUsuario); cmd.Parameters.Add(pIdUsuario); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { Pokegotchi pokegotchi = new Pokegotchi(); pokegotchi.IdUsuario = (int)dr["idUsuario"]; pokegotchi.Salud = (int)dr["salud"]; pokegotchi.IdPokemon = (int)dr["idPokemon"]; pokegotchi.Felicidad = (int)dr["felicidad"]; pokegotchi.Id = (int)dr["id"]; pokegotchi.Salud = (int)dr["salud"]; Pokemon pokemon = new Pokemon(); pokemon.NombrePokemon = (string)dr["NombrePokemon"]; pokemon.Tipo = (string)dr["Tipo"]; pokemon.IdPokegotchi = (int)dr["id"]; pokemon.IdApi = (int)dr["idApi"]; pokegotchi.Pokemon = pokemon; listaPokegotchi.Add(pokegotchi); } dr.Close(); } catch (Exception error) { } return(listaPokegotchi); }