public ApuestaDTO ToDTO(Apuesta apuesta) { int eventoId; using (PlaceMyBetContext context = new PlaceMyBetContext()) { eventoId = context.Mercados.FirstOrDefault(m => m.MercadoId == apuesta.MercadoId).EventoId; } return(new ApuestaDTO(apuesta.UsuarioId, eventoId, apuesta.Cuota, apuesta.Cantidad, apuesta.Tipo, apuesta.Mercado)); }
internal void UpdateMercadoExistente(int id, Apuesta apuesta) { Mercado mercado = QueMercadoEsLaApuesta(apuesta); mercado = RecalculoCuotas(mercado, apuesta); PlaceMyBetContext context = new PlaceMyBetContext(); context.Mercados.Update(mercado); context.SaveChanges(); }
internal List <Apuesta> ObtenerApuestasPorEmailQuery(string email, List <Usuario> users) { int idUser = -1; foreach (Usuario user in users) { if (user.Email.Equals(email)) { idUser = user.UsuarioId; break; } } MySqlConnection con = Connect(); MySqlCommand command = con.CreateCommand(); command.CommandText = "select * from apuestas where id_usuario=@idUser"; command.Parameters.AddWithValue("@idUser", idUser); try { con.Open(); MySqlDataReader res = command.ExecuteReader(); Apuesta ap = null; List <Apuesta> apuestas = new List <Apuesta>(); while (res.Read()) { Debug.WriteLine("Recuperado: " + res.GetInt32(0) + " " + res.GetDouble(1) + " " + res.GetDouble(2) + " " + res.GetString(3) + " " + res.GetInt32(4) + " " + res.GetInt32(5) + " " + res.GetInt32(6)); ap = new Apuesta(res.GetInt32(0), res.GetDouble(1), res.GetDouble(2), res.GetString(3), res.GetInt32(4), res.GetInt32(5), res.GetInt32(6)); apuestas.Add(ap); } con.Close(); return(apuestas); } catch (MySqlException) { Debug.WriteLine("Se ha producido un error de conexión."); return(null); } }
internal void UpdateMercadoExistente(int id, Apuesta apuesta) { MySqlConnection con = Connect(); MySqlCommand command = con.CreateCommand(); Mercado mercado = QueMercadoEsLaApuesta(apuesta); mercado = RecalculoCuotas(mercado, apuesta); /*command.CommandText = "UPDATE mercados SET id=@id, id_evento=@id_evento, cuota_over=@cuota_over, cuota_under=@cuota_under, dinero_over=@dinero_over," + * "dinero_under=@dinero_under, tipo_mercado=@tipo_mercado WHERE id=@id"; * * command.Parameters.AddWithValue("@id", mercado.MercadoId); * command.Parameters.AddWithValue("@id_evento", mercado.EventoId); * command.Parameters.AddWithValue("@cuota_over", mercado.CuotaOver); * command.Parameters.AddWithValue("@cuota_under", mercado.CuotaUnder); * command.Parameters.AddWithValue("@dinero_over", mercado.DineroOver); * command.Parameters.AddWithValue("@dinero_under", mercado.DineroUnder); * command.Parameters.AddWithValue("@tipo_mercado", mercado.TipoMercado); */ command.CommandText = "UPDATE mercados SET cuota_over=@cuota_over, cuota_under=@cuota_under, dinero_over=@dinero_over," + "dinero_under=@dinero_under WHERE id=@id"; command.Parameters.AddWithValue("@id", mercado.MercadoId); command.Parameters.AddWithValue("@cuota_over", mercado.CuotaOver); command.Parameters.AddWithValue("@cuota_under", mercado.CuotaUnder); command.Parameters.AddWithValue("@dinero_over", mercado.DineroOver); command.Parameters.AddWithValue("@dinero_under", mercado.DineroUnder); try { con.Open(); MySqlDataReader res = command.ExecuteReader(); con.Close(); } catch (MySqlException) { Debug.WriteLine("Se ha producido un error de conexión."); } }
internal Mercado RecalculoCuotas(Mercado mercado, Apuesta apuesta) { double probabilidadOver = 0.0; double probabilidadUnder = 0.0; string tipoApuesta = apuesta.Tipo.ToLower(); if (tipoApuesta.Contains("over")) { mercado.DineroOver += apuesta.Cantidad; } else { mercado.DineroUnder += apuesta.Cantidad; } probabilidadOver = mercado.DineroOver / (mercado.DineroOver + mercado.DineroUnder); probabilidadUnder = mercado.DineroUnder / (mercado.DineroOver + mercado.DineroUnder); mercado.CuotaOver = Math.Round(1 / probabilidadOver * 0.95, 2); mercado.CuotaUnder = Math.Round(1 / probabilidadUnder * 0.95, 2); return(mercado); }
internal Mercado QueMercadoEsLaApuesta(Apuesta apuesta) { return(BuscarMercadoPorID(apuesta.MercadoId)); }