Esempio n. 1
0
        public bool EditPlayer(JsonUser user)
        {
            using var conn = new NpgsqlConnection(ConnectionString);
            conn.Open();

            var cmd = new NpgsqlCommand("UPDATE player SET name = @name, bio = @bio, image = @image where username = @username", conn);

            cmd.Parameters.AddWithValue("username", user.Username);
            cmd.Parameters.AddWithValue("name", user.Name);
            cmd.Parameters.AddWithValue("bio", user.Bio);
            cmd.Parameters.AddWithValue("image", user.Image);
            cmd.Prepare();

            try
            {
                if (cmd.ExecuteNonQuery() != -1)
                {
                    return(true);
                }
                return(false);
            }
            catch (PostgresException)
            {
                return(false);
            }
        }
Esempio n. 2
0
        public JsonUser ShowPlayerData(string username)
        {
            using var conn = new NpgsqlConnection(ConnectionString);
            conn.Open();

            var cmd = new NpgsqlCommand("Select username, name, coins, image, bio, elo from player where username = @username", conn);

            cmd.Parameters.AddWithValue("username", username);
            cmd.Prepare();

            JsonUser user = new JsonUser();

            try
            {
                var reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    user.Username = (string)reader[0];
                    if (!(reader[1] is DBNull))
                    {
                        user.Name = (string)reader[1];
                    }
                    user.Coins = (int)reader[2];
                    if (!(reader[3] is DBNull))
                    {
                        user.Image = (string)reader[3];
                    }
                    if (!(reader[4] is DBNull))
                    {
                        user.Bio = (string)reader[4];
                    }
                    user.Elo = (int)reader[5];
                }

                return(user);
            }
            catch (PostgresException)
            {
                return(null);
            }
        }