public static int Crear(CaracteristicaVariable caracteristica) { int result = 0; using (SqlConnection Connection = new SqlConnection(Conectar.Instancia.CadenaConexion())) { string query = "INSERT INTO CaracteristicaVariable (Nombre) OUTPUT INSERTED.ID VALUES (@Nombre)"; SqlCommand Comando = new SqlCommand(query, Connection); Comando.Parameters.AddWithValue("@Nombre", caracteristica.Nombre); Connection.Open(); result = Comando.ExecuteNonQuery(); } foreach (Personaje personaje in PersonajeDA.Listar()) { using (SqlConnection Connection = new SqlConnection(Conectar.Instancia.CadenaConexion())) { string query = "INSERT INTO PersonajeCaracteristica (IdPer, IdCar, Valor) VALUES (@IdPER, @IdCAR, @Valor)"; SqlCommand Comando = new SqlCommand(query, Connection); Comando.Parameters.AddWithValue("@IdPER", personaje.Id); Comando.Parameters.AddWithValue("@IdCAR", caracteristica.Id); Comando.Parameters.AddWithValue("@Valor", 1); Connection.Open(); } } return(result); }
public static List <PersonajeCaracteristica> obtenerCaracteristicaPersonajesPorPersonaje(int id) { List <PersonajeCaracteristica> retorno = new List <PersonajeCaracteristica>(); using (SqlConnection Connection = new SqlConnection(Conectar.Instancia.CadenaConexion())) { string query = "SELECT * FROM PersonajeCaracteristica WHERE IdPer=" + id; SqlCommand Comando = new SqlCommand(query, Connection); Connection.Open(); SqlDataReader reader = Comando.ExecuteReader(); while (reader.Read()) { PersonajeCaracteristica laPersonajeCaracteristica = new PersonajeCaracteristica(); laPersonajeCaracteristica.Valor = (int)reader["Valor"]; laPersonajeCaracteristica.Personaje = PersonajeDA.Obtener((int)reader["IdPER"]); laPersonajeCaracteristica.CaracteristicaVariable = CaracteristicaVariableDA.Obtener((int)reader["IdCAR"]); retorno.Add(laPersonajeCaracteristica); } } return(retorno); }
public static Clase Obtener(int id) { Clase retorno = null; using (SqlConnection Connection = new SqlConnection(Conectar.Instancia.CadenaConexion())) { string query = "SELECT Id,Nombre, Descripcion FROM Clase WHERE Id = @Id"; SqlCommand Comando = new SqlCommand(query, Connection); Comando.Parameters.AddWithValue("@Id", id); Connection.Open(); SqlDataReader reader = Comando.ExecuteReader(); if (reader.Read()) { retorno = new Clase(); retorno.Id = (int)reader["Id"]; retorno.Nombre = reader["Nombre"].ToString(); retorno.Descripcion = reader["Descripcion"].ToString(); retorno.Personajes = PersonajeDA.ObtenerPorClase(retorno.Id); } } return(retorno); }
public static List <Raza> Listar() { List <Raza> retorno = new List <Raza>(); using (SqlConnection Connection = new SqlConnection(Conectar.Instancia.CadenaConexion())) { string query = "SELECT Id, Nombre, Descripcion FROM Raza"; SqlCommand Comando = new SqlCommand(query, Connection); Connection.Open(); SqlDataReader reader = Comando.ExecuteReader(); while (reader.Read()) { Raza laRaza = new Raza(); laRaza.Id = (int)reader["Id"]; laRaza.nombre = reader["Nombre"].ToString(); laRaza.Descripcion = reader["Descripcion"].ToString(); laRaza.Personajes = PersonajeDA.ObtenerPorRaza(laRaza.Id); laRaza.CaracteristicaVariable = CaracteristicaVariableDA.ObtenerPorRaza(laRaza.Id); retorno.Add(laRaza); } } return(retorno); }