Ejemplo n.º 1
0
        public static User GetFullUserFromDb(int UserId)
        {
            User UserFromDb = new User();

            UserFromDb.Id = UserId;

            string connStr = ConfigurationManager.ConnectionStrings["HogwartsDatabase"].ConnectionString;

            using (MySqlConnection conn = new MySqlConnection(connStr))
            {
                using (MySqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "SELECT antworten.id as id_antwort, id_frage, antworttext, fragentext, hintergrundfarbe FROM antworten INNER JOIN fragen ON antworten.id_frage = fragen.id INNER JOIN hausinfos ON antworten.id_haus = hausinfos.id;";
                    conn.Open();
                    MySqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Frage fra = UserFromDb.Fragebogen.Where(x => x.Id == reader.GetInt32("id_frage")).FirstOrDefault();
                        if (fra == null)
                        {
                            fra = new Frage(reader.GetInt32("id_frage"), reader.GetString("fragentext"));
                            UserFromDb.Fragebogen.Add(fra);
                        }
                        Antwort aw = new Antwort(fra, reader.GetInt32("id_antwort"), reader.GetString("antworttext"));
                        aw.Farbe = reader.GetString("hintergrundfarbe");
                        fra.Antworten.Add(aw);
                    }
                    reader.Close();

                    cmd.CommandText = string.Format("SELECT id_antwort, id_letzte_frage, username FROM users INNER JOIN users_antworten ON users.id = users_antworten.id_user WHERE users.id = {0};", UserId);
                    reader          = cmd.ExecuteReader();
                    bool letzteFrageErledigt = false;
                    while (reader.Read())
                    {
                        if (letzteFrageErledigt == false)
                        {
                            UserFromDb.SetVorherigeFrage(reader.GetInt32("id_letzte_frage"));
                            UserFromDb.Name     = reader.GetString("username");
                            letzteFrageErledigt = true;
                        }
                        foreach (Frage fra in UserFromDb.Fragebogen)
                        {
                            foreach (Antwort aw in fra.Antworten)
                            {
                                if (aw.Id == reader.GetInt32("id_antwort"))
                                {
                                    aw.Ausgewaehlt = true;
                                }
                            }
                        }
                    }
                    reader.Close();
                    conn.Close();
                }
            }
            return(UserFromDb);
        }
Ejemplo n.º 2
0
        public string GetFarbe()
        {
            Antwort a = this.Antworten.Where(x => x.Ausgewaehlt == true).FirstOrDefault();

            if (a != null)
            {
                return(a.Farbe);
            }
            else
            {
                return("#efefef");
            }
        }