Example #1
0
        internal List <ApuestaDTO> RetrieveDTO()
        {
            ///*MySqlConnection con = Connect();
            //MySqlCommand command = con.CreateCommand();
            //command.CommandText = "select * from apuesta";*/
            //try
            //{
            //    /*con.Open();
            //    MySqlDataReader reader = command.ExecuteReader();
            //    List<ApuestaDTO> apuestas = new List<ApuestaDTO>();
            //    while (reader.Read())
            //    {
            //        apuestas.Add(new ApuestaDTO(reader.GetString(1), reader.GetInt32(2), reader.GetInt32(3), reader.GetInt32(4), reader.GetString(5)));
            //    }
            //    con.Close();*/
            //    //return null;
            //}
            //catch (/*MySqlException ex*/ InvalidCastException e)
            //{
            //    Console.WriteLine("Se ha producido un error: " + e);
            //    //return null;
            //}



            using (var context = new PlaceMyBetContext())
            {
                List <ApuestaDTO> apuestas = context.Apuestas.Include(a => a.Mercado).Select(a => ToDTO(a)).ToList();
                return(apuestas);
            }
        }
        //private MySqlConnection Connect()
        //{
        //    string connString = "Server=localhost;Port=3306;Database=PlaceMyBet;Uid=root;password="******"select * from usuario";

            //try
            //{
            //    con.Open();
            //    MySqlDataReader res = command.ExecuteReader();

            //    Usuario a = null;
            //    List<Usuario> lista = new List<Usuario>();
            //    while (res.Read())
            //    {
            //        Debug.WriteLine("Recuperado: " + res.GetString(0) + " " + res.GetString(1) + " " + res.GetString(2) + " " + res.GetInt32(3));
            //        a = new Usuario(res.GetString(0), res.GetString(1), res.GetString(2), res.GetInt32(3));
            //        lista.Add(a);
            //    }

            //    return lista;
            //}
            //catch (MySqlException e)
            //{
            //    Debug.WriteLine("Se ha producido un error de conexion");
            //    return null;
            //}
            List <Usuario> usuarios = new List <Usuario>();

            using (PlaceMyBetContext context = new PlaceMyBetContext())
            {
                usuarios = context.Usuarios.ToList();
            }
            return(usuarios);
        }
Example #3
0
        internal void Save(Evento e)
        {
            PlaceMyBetContext context = new PlaceMyBetContext();

            context.Eventos.Add(e);
            context.SaveChanges();
        }
Example #4
0
        /* private MySqlConnection Connect()
         * {
         *
         *  string connString = "Server=127.0.0.1;Port=3306;Database=placemybet;Uid=root;Password=;SslMode=none";
         *   MySqlConnection con = new MySqlConnection(connString);
         *   return con;
         *
         * }*/

        internal List <MercadoDTO> RetrieveList()
        {
            /*
             * using (PlaceMyBetContext context = new PlaceMyBetContext())
             * {
             *  List<Apuesta> apuesta = context.Apuestas.Include(a => a.Mercado).ToList();
             *  List<Mercado> mercado = context.Mercados.Include(evento => evento.Evento).ToList();
             *  return mercado;
             * }*/

            using (PlaceMyBetContext context = new PlaceMyBetContext())
            {
                List <MercadoDTO> eventos = context.Mercados.Select(p => ToDTO(p)).ToList();
                return(eventos);
            }

            /* MySqlConnection con = Connect();
             * MySqlCommand command = con.CreateCommand();
             * command.CommandText = "SELECT * FROM Mercado";
             *
             * con.Open();
             * MySqlDataReader res = command.ExecuteReader();
             *
             * MercadoDTO m = null;
             *
             * if (res.Read())
             * {
             *
             *   Debug.WriteLine("Recuparado: " + res.GetDouble(1) + res.GetDouble(2) + res.GetDouble(3));
             *   m = new MercadoDTO(res.GetDouble(1), res.GetDouble(2), res.GetDouble(3));
             * }*/

            //return m;
        }
Example #5
0
        internal void Recalculate(int mercadoId)
        {
            try
            {
                using (var context = new PlaceMyBetContext())
                {
                    double resOver  = context.Apuestas.Where(m1 => m1.MercadoId == mercadoId & m1.TipoApuesta == 0).Select(i1 => i1.Importe).Sum();
                    double resUnder = context.Apuestas.Where(m2 => m2.MercadoId == mercadoId & m2.TipoApuesta == 1).Select(i2 => i2.Importe).Sum();

                    double total = resOver + resUnder;

                    double probOver  = resOver / total;
                    double cuotaOver = 0.95 / probOver;

                    double probUnder  = resUnder / total;
                    double cuotaUnder = 0.95 / probUnder;

                    var mercado = context.Mercados.First(m => m.Id == mercadoId);
                    mercado.COver  = cuotaOver;
                    mercado.CUnder = cuotaUnder;
                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Error al añadir un apuesta");
            }
        }
Example #6
0
        /*private MySqlConnection Connect()
         * {
         *  string connString = "Server =127.0.0.1;Port=3306;Database=placemybet1;Uid=root;password=;SslMode=none";
         *  MySqlConnection con = new MySqlConnection(connString);
         *  return con;
         * }*/
        internal List <Evento> Retrieve()
        {
            List <Evento> eventos = new List <Evento>();

            using (PlaceMyBetContext context = new PlaceMyBetContext())
            {
                eventos = context.Eventos.ToList();
            }
            return(eventos);

            //  MySqlConnection con = Connect();
            //  MySqlCommand command = con.CreateCommand();
            // command.CommandText = "SELECT * FROM evento";

            // con.Open();
            //  MySqlDataReader res = command.ExecuteReader();

            // Evento e = null;
            //  if (res.Read())
            //  {
            //      Debug.WriteLine("Recuperado: " + res.GetString(1) + " " + res.GetString(2) + " " + res.GetString(3));
            //     e = new EventoDTO(res.GetString(1), res.GetString(2), res.GetString(3));
            // }
            // return e;
            // return null;
        }
        //private MySqlConnection Connect()
        //{
        //    string connString = "Server=localhost;Port=3306;Database=PlaceMyBet;Uid=root;password="******"select * from apuesta";

            //try
            //{
            //    con.Open();
            //    MySqlDataReader res = command.ExecuteReader();

            //    Apuesta a = null;
            //    List<Apuesta> listaApuestas = new List<Apuesta>();
            //    while (res.Read())
            //    {
            //        Debug.WriteLine("Recuperado: " + res.GetInt32(0) + " " + res.GetDouble(1) + " " + res.GetDouble(2) + " " + res.GetDouble(3) + " " + res.GetString(4) + " " + res.GetInt32(5) + " " + res.GetString(6) + " " + res.GetString(7));
            //        a = new Apuesta(res.GetInt32(0), res.GetDouble(1), res.GetDouble(2), res.GetDouble(3), res.GetString(4), res.GetInt32(5), res.GetString(6), res.GetString(7));
            //        listaApuestas.Add(a);
            //    }

            //    return listaApuestas;
            //}catch(MySqlException e)
            //{
            //    Debug.WriteLine("Se ha producido un error de conexion");
            //    return null;
            //}
            List <Apuesta> apuestas = new List <Apuesta>();

            using (PlaceMyBetContext context = new PlaceMyBetContext())
            {
                apuestas = context.Apuestas.ToList();
                apuestas = context.Apuestas.Include(p => p.Mercado).ToList();
            }
            return(apuestas);
        }
Example #8
0
        internal List <EventoDTO2> RetrieveDTO()
        {
            //MySqlConnection con = Connect();
            //MySqlCommand command = con.CreateCommand();
            //command.CommandText = "select * from evento";

            //try
            //{
            //    con.Open();
            //    MySqlDataReader res = command.ExecuteReader();

            //    EventoDTO a = null;
            //    List<EventoDTO> lista = new List<EventoDTO>();
            //    while (res.Read())
            //    {
            //        Debug.WriteLine("Recuperado: "+ res.GetString(1) + " " + res.GetString(2) + " " + res.GetString(3));
            //        a = new EventoDTO(res.GetString(1), res.GetString(2), res.GetString(3));
            //        lista.Add(a);
            //    }

            //    return lista;
            //}
            //catch (MySqlException e)
            //{
            //    Debug.WriteLine("Se ha producido un error de conexion");
            //    return null;
            //}
            List <EventoDTO2> eventos = new List <EventoDTO2>();

            using (PlaceMyBetContext context = new PlaceMyBetContext())
            {
                eventos = context.Eventos.Select(p => ToDTO2(p)).ToList();
            }
            return(eventos);
        }
Example #9
0
        internal void save(Mercado mercado)
        {
            PlaceMyBetContext context = new PlaceMyBetContext();

            context.Add(mercado);
            context.SaveChanges();
        }
Example #10
0
        internal Mercado Retrieve(int id)
        {
            Mercado mercado;

            using (PlaceMyBetContext context = new PlaceMyBetContext())
            {
                mercado = context.Mercados.Where(m => m.MercadoID == id)
                          .FirstOrDefault();
            }

            /* MySqlConnection con = Connect();
             * MySqlCommand command = con.CreateCommand();
             * command.CommandText = "SELECT * FROM Mercado";
             *
             * con.Open();
             * MySqlDataReader res = command.ExecuteReader();
             *
             * MercadoDTO m = null;
             *
             * if (res.Read())
             * {
             *
             *   Debug.WriteLine("Recuparado: " + res.GetDouble(1) + res.GetDouble(2) + res.GetDouble(3));
             *   m = new MercadoDTO(res.GetDouble(1), res.GetDouble(2), res.GetDouble(3));
             * }*/

            //return m;
            return(mercado);
        }
Example #11
0
        internal List <Mercado> Retrieve()
        {
            List <Mercado> mercado = new List <Mercado>();

            using (PlaceMyBetContext context = new PlaceMyBetContext())
            {
                mercado = context.Mercados.ToList();
            }
            return(mercado);
            // MySqlConnection con = Connect();
            // MySqlCommand command = con.CreateCommand();
            //command.CommandText = "SELECT * FROM mercado";

            // con.Open();
            //MySqlDataReader res = command.ExecuteReader();


            //if (res.Read())
            //  {

            // Debug.WriteLine("Recuperado: " + res.GetDouble(1) + " " + res.GetDouble(2) + " " + res.GetDouble(3));
            //  m = new MercadoDTO(res.GetDouble(1), res.GetDouble(2), res.GetDouble(3));
            //  }
            // return m;
        }
        internal void Save(Mercado m)
        {
            PlaceMyBetContext context = new PlaceMyBetContext();

            context.Mercados.Add(m);
            context.SaveChanges();
        }
Example #13
0
        /*  private MySqlConnection Connect()
         * {
         *
         *    string connString = "Server=127.0.0.1;Port=3306;Database=placemybet;Uid=root;Password=;SslMode=none";
         *    MySqlConnection con = new MySqlConnection(connString);
         *    return con;
         *
         * }*/
        internal List <EventoDTO> RetrieveList()
        {
            using (PlaceMyBetContext context = new PlaceMyBetContext())
            {
                List <EventoDTO> eventos = context.Eventos.Select(p => ToDTO(p)).ToList();
                return(eventos);
            }

            /* MySqlConnection con = Connect();
             * MySqlCommand command = con.CreateCommand();
             * command.CommandText = "SELECT * FROM Evento";
             *
             * con.Open();
             * MySqlDataReader res = command.ExecuteReader();
             *
             * EventoDTO e = null;
             *
             * if (res.Read())
             * {
             *   Debug.WriteLine("Recuperado: " + res.GetString(1) + res.GetString(2) + res.GetString(3));
             *   e = new EventoDTO(res.GetString(1), res.GetString(2), res.GetString(3));
             * }*/


            //return e;
        }
Example #14
0
        internal void Save(Partido p)
        {
            var context = new PlaceMyBetContext();

            context.Partidos.Add(p);
            context.SaveChanges();
        }
Example #15
0
        internal void Save(Apuesta a)
        {
            try
            {
                using (var context = new PlaceMyBetContext())
                {
                    var apuesta = new Apuesta
                    {
                        UsuarioId   = a.UsuarioId,
                        Importe     = a.Importe,
                        MercadoId   = a.MercadoId,
                        Cuota       = a.Cuota,
                        TipoApuesta = a.TipoApuesta,
                        Fecha       = a.Fecha,
                    };
                    context.Apuestas.Add(apuesta);
                    context.SaveChanges();

                    this.Recalculate(a.MercadoId);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Error al añadir un apuesta");
            }
        }
Example #16
0
 internal List <MercadoDTO> RetrieveDTO()
 {
     using (var context = new PlaceMyBetContext())
     {
         List <MercadoDTO> mercados = context.Mercados.Select(m => ToDTO(m)).ToList();
         return(mercados);
     }
 }
Example #17
0
 /*private MySqlConnection Connect()
  * {
  *  string connString = "Server=localhost;Port=3306;Database=mydb;Uid=root;password=;SslMode=none";
  *  MySqlConnection con = new MySqlConnection(connString);
  *  return con;
  * }*/
 internal List <Apuesta> Retrieve()
 {
     using (var context = new PlaceMyBetContext())
     {
         List <Apuesta> apuestas = context.Apuestas.Include(a => a.Mercado).ToList();
         return(apuestas);
     }
 }
Example #18
0
 internal void Delete(int id)
 {
     using (var context = new PlaceMyBetContext())
     {
         context.Eventos.Remove(context.Eventos.FirstOrDefault(e => e.EventoId == id));
         context.SaveChanges();
     }
 }
Example #19
0
 public List <ApuestaDTOID> RetrieveBYC(double cuota)
 {
     using (var context = new PlaceMyBetContext())
     {
         List <ApuestaDTOID> apuestas = context.Apuestas.Where(a => a.Cuota < cuota).Select(a => ToDTOID(a)).ToList();
         return(apuestas);
     }
 }
Example #20
0
 internal List <Evento> Retrieve()
 {
     using (var context = new PlaceMyBetContext())
     {
         var eventos = context.Eventos.ToList();
         return(eventos);
     }
 }
Example #21
0
        internal void Delete(int id)
        {
            PlaceMyBetContext context = new PlaceMyBetContext();

            Partido partido = Retrieve(id);

            context.Partidos.Remove(partido);
            context.SaveChanges();
        }
Example #22
0
 internal List <Mercado> Retrieve()
 {
     using (var context = new PlaceMyBetContext())
     {
         //var mercados = context.Mercados.ToList();
         List <Mercado> mercados = context.Mercados.Include(p => p.Evento).ToList();
         return(mercados);
     }
 }
Example #23
0
 internal void Save(Mercado m)
 {
     using (var context = new PlaceMyBetContext())
     {
         var mercados = context.Set <Mercado>();
         mercados.Add(m);
         context.SaveChanges();
     }
 }
Example #24
0
 internal Mercado RetrieveById(int id_mercado)
 {
     using (var context = new PlaceMyBetContext())
     {
         var mercado = context.Mercados
                       .FirstOrDefault(m => m.MercadoId == id_mercado);
         return(mercado);
     }
 }
Example #25
0
 internal Apuesta RetrieveById(int id_apuesta)
 {
     using (var context = new PlaceMyBetContext())
     {
         var apuesta = context.Apuestas
                       .FirstOrDefault(a => a.ApuestaId == id_apuesta);
         return(apuesta);
     }
 }
        internal Mercado RetrievebyId(int id)
        {
            Mercado m;

            using (var context = new PlaceMyBetContext())
            {
                m = context.Mercados.Single(b => b.MercadoId == id);
            }
            return(m);
        }
        /// <summary>
        /// muestro todos los eventos
        /// </summary>
        /// <returns>devuelvo una lista de eventos</returns>
        internal List <Evento> Retrieve() //internal es como un public pero un poco mas restrictivo
        {
            List <Evento> eventos = new List <Evento>();

            using (PlaceMyBetContext context = new PlaceMyBetContext())
            {
                eventos = context.Evento.ToList();
            }
            return(eventos);
        }
        internal Apuesta RetrievebyId(int id)
        {
            Apuesta a;

            using (var context = new PlaceMyBetContext())
            {
                a = context.Apuestas.Single(b => b.ApuestaId == id);
            }
            return(a);
        }
Example #29
0
 internal void Update(int id, string equipol, string equipov)
 {
     using (var context = new PlaceMyBetContext())
     {
         Evento evento = context.Eventos.FirstOrDefault(e => e.EventoId == id);
         evento.EquipoL = equipol;
         evento.EquipoV = equipov;
         context.SaveChanges();
     }
 }
        /*private MySqlConnection Connect()
         * {
         *  string connString = "Server =127.0.0.1;Port=3306;Database=placemybet1;Uid=root;password=;SslMode=none";
         *  MySqlConnection con = new MySqlConnection(connString);
         *  return con;
         * }*/
        internal List <Apuesta> Retrieve()
        {
            List <Apuesta> apuesta = new List <Apuesta>();

            using (PlaceMyBetContext context = new PlaceMyBetContext())
            {
                apuesta = context.Apuestas.ToList();
            }
            return(apuesta);
        }