internal void Save(Apuesta a)
        {
            DDBBContext context = new DDBBContext();

            context.Apuestas.Add(a);
            context.SaveChanges();

            Mercado mer = new Mercado();

            mer = context.Mercados
                  .Where(m => m.MercadoID == a.MercadoID).FirstOrDefault();


            if (a.Tipo_apuesta == 0)
            {
                mer.Dinero_under += a.Dinero_apostado;
            }
            else
            {
                mer.Dinero_over += a.Dinero_apostado;
            }

            var probOver  = mer.Dinero_over / (mer.Dinero_under + mer.Dinero_over);
            var probUnder = mer.Dinero_under / (mer.Dinero_over + mer.Dinero_under);

            mer.Cuota_under = Math.Round(Convert.ToDouble((1 / probOver) * 0.95));
            mer.Cuota_over  = Math.Round(Convert.ToDouble((1 / probUnder) * 0.95));

            context.Mercados.Update(mer);
            context.SaveChanges();
        }
Example #2
0
        internal List <Mercado> Retrieve()
        {
            MySqlConnection con     = Connect();
            MySqlCommand    command = con.CreateCommand();

            command.CommandText = "select * from mercado";

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

                Mercado        m       = null;
                List <Mercado> mercado = new List <Mercado>();
                while (res.Read())
                {
                    Debug.WriteLine("Recuperado: " + res.GetInt32(0) + " " + res.GetDouble(1) + " " + res.GetDouble(2) + " " + res.GetDouble(3) + " " + res.GetDouble(4) + " " + res.GetInt32(5));

                    m = new Mercado(res.GetInt32(0), res.GetDouble(1), res.GetDouble(2), res.GetDouble(3), res.GetDouble(4), res.GetInt32(5));

                    mercado.Add(m);
                }

                con.Close();
                return(mercado);
            }

            catch (MySqlException e)
            {
                Debug.WriteLine("Se ha producido un error de conexion");
                return(null);
            }
        }
Example #3
0
        internal List <Mercado> Retrieve()
        {
            MySqlConnection con     = Connect();
            MySqlCommand    command = con.CreateCommand();

            command.CommandText = "select * from mercados";


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

                Mercado        m        = null;
                List <Mercado> mercados = new List <Mercado>();

                while (res.Read())
                {
                    Debug.WriteLine("Datos de mercado: id: " + res.GetInt32(0) + " id_evento: " + res.GetString(1) +
                                    " over_under " + res.GetDouble(2) + " cuota_over: " + res.GetDouble(3) + " cuota_under " + res.GetDouble(4)
                                    + " dinero_over " + res.GetDouble(5) + " dinero_under " + res.GetDouble(6));
                    m = new Mercado(res.GetInt32(0), res.GetInt32(1), res.GetDouble(2), res.GetDouble(3), res.GetDouble(4), res.GetDouble(5)
                                    , res.GetDouble(6));
                    mercados.Add(m);
                }
                con.Close();
                return(mercados);
            }
            catch (MySqlException e)
            {
                Debug.WriteLine("Error de conexión");
                return(null);
            }
        }
Example #4
0
        internal List <Mercado> RetrieveIdEvento(int id_evento)
        {
            MySqlConnection con     = Connect();
            MySqlCommand    command = con.CreateCommand();

            command.CommandText = "select over_under, cuota_over, cuota_under from mercados where eventos_id_evento=" + id_evento;


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

                Mercado        m        = null;
                List <Mercado> partidos = new List <Mercado>();

                while (res.Read())
                {
                    Debug.WriteLine("Cuotas de mercado:  tipo de mercado: " + res.GetDouble(0) +
                                    " cuota over " + res.GetDouble(1) + " cuota under: " + res.GetDouble(2));

                    m = new Mercado(res.GetDouble(0), res.GetDouble(1), res.GetDouble(2));
                    partidos.Add(m);
                }
                con.Close();
                return(partidos);
            }
            catch (MySqlException e)
            {
                Debug.WriteLine("Error de conexión");
                return(null);
            }
        }
        //insertar mercado
        internal void Save(Mercado e)
        {
            DDBBContext context = new DDBBContext();

            context.Mercados.Add(e);
            context.SaveChanges();
        }
Example #6
0
 public ApuestaDTO(int id_apuesta, int id_evento, int id_usuario, int tipo_apuesta, double cuota, double dinero_apostado, Mercado mercado)
 {
     ApuestaID       = id_apuesta;
     EventoID        = id_evento;
     UsuarioID       = id_usuario;
     Tipo_apuesta    = tipo_apuesta;
     Cuota           = cuota;
     Dinero_apostado = dinero_apostado;
     Mercado         = mercado;
 }
Example #7
0
        internal void insertarMercado(Mercado m)
        {
            CultureInfo culInfo = new System.Globalization.CultureInfo("es-ES");

            culInfo.NumberFormat.NumberDecimalSeparator = ".";

            culInfo.NumberFormat.CurrencyDecimalSeparator        = ".";
            culInfo.NumberFormat.PercentDecimalSeparator         = ".";
            culInfo.NumberFormat.CurrencyDecimalSeparator        = ".";
            System.Threading.Thread.CurrentThread.CurrentCulture = culInfo;


            Debug.WriteLine("apuesta vale " + m);

            MySqlConnection con     = Connect();
            MySqlCommand    command = con.CreateCommand();

            command.CommandText = "insert into mercado (id_mercado,tipo_mercado, cuota_over, cuota_under, dinero_over, dinero_under, id_evento) values ('" + m.Id_mercado + "','" + m.Tipo_mercado + "' ,'" + m.Cuota_over + "' ,'" + m.Cuota_under + "','" + m.Dinero_over + "','" + m.Dinero_under + "','" + m.Id_evento + "');";
            command.CommandText = "insert into mercado (id_mercado,tipo_mercado, cuota_over, cuota_under, dinero_over, dinero_under, id_evento) values ('" + m.Id_mercado + "','" + m.Tipo_mercado + "' ,'" + m.Cuota_over + "' ,'" + m.Cuota_under + "','" + m.Dinero_over + "','" + m.Dinero_under + "','" + m.Id_evento + "');";
            command.CommandText = "insert into mercado (id_mercado,tipo_mercado, cuota_over, cuota_under, dinero_over, dinero_under, id_evento) values ('" + m.Id_mercado + "','" + m.Tipo_mercado + "' ,'" + m.Cuota_over + "' ,'" + m.Cuota_under + "','" + m.Dinero_over + "','" + m.Dinero_under + "','" + m.Id_evento + "');";
            Debug.WriteLine("comando " + command.CommandText);



            try
            {
                con.Open();
                command.ExecuteNonQuery();
                con.Close();
            }
            catch (MySqlException)
            {
                Debug.WriteLine("Se ha producido un error de conexión");
                con.Close();
            }
        }
Example #8
0
 public EventoExamen(string local, string visitante, Mercado mercado)
 {
     Local     = local;
     Visitante = visitante;
     Mercado   = mercado;
 }
 //mercadoDTO muestra mercado solo con la informacion pedida
 public MercadoDTO ToDTO(Mercado m)
 {
     return(new MercadoDTO(m.Over_under, m.Cuota_over, m.Cuota_under));
 }