internal void Save(Partido p) { var context = new PlaceMyBetContext(); context.Partidos.Add(p); context.SaveChanges(); }
internal List <Partido> Retrieve() { MySqlConnection con = Connect(); MySqlCommand command = con.CreateCommand(); command.CommandText = "select * from partido"; try { con.Open(); MySqlDataReader res = command.ExecuteReader(); Partido p = null; List <Partido> partidos = new List <Partido>(); while (res.Read()) { Debug.WriteLine("Recuperado: " + res.GetInt32(0) + " " + res.GetString(1) + " " + res.GetString(2) + " " + res.GetDateTime(3)); p = new Partido(res.GetInt32(0), res.GetString(1), res.GetString(2), res.GetDateTime(3)); partidos.Add(p); } con.Close(); return(partidos); } catch (MySqlException e) { Debug.WriteLine("Error al conectar con la base de datos"); return(null); } }
internal void Delete(int id) { PlaceMyBetContext context = new PlaceMyBetContext(); Partido partido = Retrieve(id); context.Partidos.Remove(partido); context.SaveChanges(); }
internal void Update(int id, Partido p) { PlaceMyBetContext context = new PlaceMyBetContext(); Partido partido = Retrieve(id); partido.Local = p.Local; partido.Visitante = p.Visitante; context.SaveChanges(); }
internal Partido Retrieve(int id) { var partido = new Partido(); using (var context = new PlaceMyBetContext()) { partido = context.Partidos .Where(p => p.Id == id) .FirstOrDefault(); } return(partido); }
internal void Save(Partido p) { MySqlConnection con = Connect(); MySqlCommand command = con.CreateCommand(); command.CommandText = "insert into partido(local, visitante, hora) values ('" + p.Local + "','" + p.Visitante + "','" + p.Hora + "');"; try { con.Open(); command.ExecuteNonQuery(); con.Close(); } catch (MySqlException e) { Debug.WriteLine("Error al conectar con la base de datos"); } }
// Visibilidad para que sea visto por otras clases internal - como protected. internal Partido Retrieve() { //Class1 c = new Class1(1, "aaa", 1995, 2); MySql.Data.MySqlClient.MySqlConnection c = Connect(); MySql.Data.MySqlClient.MySqlCommand cmd = c.CreateCommand(); cmd.CommandText = " select * from futbol"; c.Open(); MySql.Data.MySqlClient.MySqlDataReader res = cmd.ExecuteReader(); Partido c1 = null; if (res.Read()) { Debug.WriteLine("Recupera: " + res.GetInt32(0) + " " + res.GetString(1) + " " + res.GetString(2) + " " + res.GetString(3) + " "); c1 = new Partido(res.GetInt32(0), res.GetString(1), res.GetBoolean(2), res.GetString(3)); } c.Close(); return(c1); }
public PartidoDTO ToDTO(Partido p) { return(new PartidoDTO(p.Local, p.Visitante)); }