Exemplo n.º 1
0
        internal void Save(Partido p)
        {
            var context = new PlaceMyBetContext();

            context.Partidos.Add(p);
            context.SaveChanges();
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        internal void Delete(int id)
        {
            PlaceMyBetContext context = new PlaceMyBetContext();

            Partido partido = Retrieve(id);

            context.Partidos.Remove(partido);
            context.SaveChanges();
        }
Exemplo n.º 4
0
        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();
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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");
            }
        }
Exemplo n.º 7
0
        // 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);
        }
Exemplo n.º 8
0
 public PartidoDTO ToDTO(Partido p)
 {
     return(new PartidoDTO(p.Local, p.Visitante));
 }