internal void Save(Apuesta a) { PlaceMyBetContext context = new PlaceMyBetContext(); context.Apuestas.Add(a); context.SaveChanges(); Mercado mer = new Mercado(); mer = context.Mercados .Where(m => m.MercadoId == a.MercadoId).FirstOrDefault(); if (a.TipoApuesta == 0) { mer.Dinero_under += a.DineroApostado; } else { mer.Dinero_over += a.DineroApostado; } var probabilidadOver = mer.Dinero_over / (mer.Dinero_under + mer.Dinero_over); var probabilidadUnder = mer.Dinero_under / (mer.Dinero_over + mer.Dinero_under); mer.Cuota_under = Math.Round(Convert.ToDouble((1 / probabilidadOver) * 0.95)); mer.Cuota_over = Math.Round(Convert.ToDouble((1 / probabilidadUnder) * 0.95)); context.Mercados.Update(mer); context.SaveChanges(); }
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("recuperamos: " + res.GetInt32(0) + " " + res.GetInt32(1) + " " + res.GetFloat(2) + " " + res.GetFloat(3) + " " + res.GetFloat(4) + " " + res.GetInt32(5) + " " + res.GetInt32(6)); m = new Mercado(res.GetInt32(0), res.GetInt32(1), res.GetFloat(2), res.GetFloat(3), res.GetFloat(4), res.GetInt32(5), res.GetInt32(6)); mercados.Add(m); } con.Close(); return(mercados); } catch (MySqlException e) { Debug.WriteLine("se ha producido un error de conexión"); return(null); } }
internal void Save(Mercado m) { PlaceMyBetContext context = new PlaceMyBetContext(); context.Mercados.Add(m); context.SaveChanges(); }
internal Mercado RetrieveMercado(int id, double tipo) { MySqlConnection con = conect(); MySqlCommand command = con.CreateCommand(); command.CommandText = "SELECT * FROM Mercado where ID_Evento= @id && OverUnder=@tipo"; command.Parameters.AddWithValue("@id", id); command.Parameters.AddWithValue("@tipo", tipo); con.Open(); MySqlDataReader res = command.ExecuteReader(); Mercado m = null; if (res.Read()) { m = new Mercado(res.GetInt32(0), res.GetDouble(1), res.GetDouble(2), res.GetDouble(3), res.GetDouble(4), res.GetDouble(5), res.GetInt32(6)); } con.Close(); return(m); }
internal Mercado Retrieve() { MySqlConnection con = conect(); MySqlCommand command = con.CreateCommand(); command.CommandText = "select * from Mercado"; con.Open(); MySqlDataReader res = command.ExecuteReader(); Mercado m = null; if (res.Read()) { m = new Mercado(res.GetInt32(0), res.GetDouble(1), res.GetDouble(2), res.GetDouble(3), res.GetDouble(4), res.GetDouble(5), res.GetInt32(6)); } return(m); }
internal List <Mercado> RetrieveByTipoandId(int id, float tipo) { 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; MySqlConnection con = Connect(); MySqlCommand command = con.CreateCommand(); Debug.WriteLine("hola" + id + " " + tipo); command.CommandText = "SELECT * FROM mercados WHERE ID_Evento= " + id + " AND Over_Under= '" + tipo + "'"; command.Parameters.AddWithValue("@id", id); command.Parameters.AddWithValue("@tipo", tipo); Debug.WriteLine("consula:" + command.CommandText); try { con.Open(); MySqlDataReader res = command.ExecuteReader(); Mercado m = null; List <Mercado> mercados = new List <Mercado>(); while (res.Read()) { Debug.WriteLine("recuperamos2: " + res.GetInt32(0) + " " + res.GetInt32(1) + " " + res.GetFloat(2) + " " + res.GetFloat(3) + " " + res.GetFloat(4) + " " + res.GetInt32(5) + " " + res.GetInt32(6)); m = new Mercado(res.GetInt32(0), res.GetInt32(1), res.GetFloat(2), res.GetFloat(3), res.GetFloat(4), res.GetInt32(5), res.GetInt32(6)); mercados.Add(m); } con.Close(); return(mercados); } catch (MySqlException e) { Debug.WriteLine("se ha producido un error de conexión"); return(null); } }
internal void Calculos(ApuestaDTO Apuesta, Mercado Dinero) { MySqlConnection con = conect(); MySqlCommand command = con.CreateCommand(); double probabilidadOver = Dinero.DineroOver / (Dinero.DineroOver + Dinero.DineroUnder); double cuotaOver = 0; double over = 0.95; if (probabilidadOver != 0) { cuotaOver = 1 / probabilidadOver * 0.95; over = Math.Round((double)Convert.ToDouble(cuotaOver), 2); } double probabilidadUnder = Dinero.DineroUnder / (Dinero.DineroOver + Dinero.DineroUnder); double cuotaUnder = 0; double under = 0.95; if (probabilidadUnder != 0) { cuotaUnder = 1 / probabilidadUnder * 0.95; under = Math.Round((double)Convert.ToDouble(cuotaUnder), 2); } Debug.WriteLine("under: " + cuotaUnder + "dineroOver: " + Dinero.DineroOver + "dineroUnder: " + Dinero.DineroUnder + "probabilidad: " + probabilidadUnder); Debug.WriteLine("under: " + under); con.Open(); command.CommandText = "UPDATE Mercado SET CuotaUnder=" + under.ToString(CultureInfo.CreateSpecificCulture("us-US")) + ", CuotaOver =" + over.ToString(CultureInfo.CreateSpecificCulture("us-US")) + " WHERE ID= " + Dinero.Id + ";"; Debug.WriteLine("Comando: " + command.CommandText); command.ExecuteNonQuery(); }
public MercadosDTO ToDTO(Mercado m) { return(new MercadosDTO(m.Tipo_mercado, m.Cuota_under, m.Cuota_over)); }