Exemplo n.º 1
0
        /// <summary>
        /// TODO: Shouldn't we move this to the user class?
        /// </summary>
        /// <param name="dbconn"></param>
        /// <param name="uid"></param>
        /// <returns></returns>
        public static List <Character> RetrieveCharacters(MySqlConnection dbconn, ulong uid)
        {
            /*var command = new MySqlCommand(
             *  "SELECT Characters.*, vehicles.carType, vehicles.baseColor, teams.TEAMNAME, teams.TMARKID, teams.TEAMRANKING, teams.CLOSEDATE FROM Characters LEFT JOIN teams ON characters.TeamId = teams.TID LEFT JOIN vehicles ON characters.CurrentCarID = vehicles.CID WHERE characters.UID = @uid",
             *  dbconn);*/
            var command = new MySqlCommand(
                "SELECT * FROM Characters WHERE characters.UID = @uid",
                dbconn);

            command.Parameters.AddWithValue("@uid", uid);

            var chars = new List <Character>();

            using (DbDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    var character = CharacterModel.GetCharacter(dbconn, reader);
                    chars.Add(character);
                }
            }

            foreach (var character in chars)
            {
                character.GarageVehicles = VehicleModel.Retrieve(dbconn, character.Id);
                character.ActiveCar      =
                    character.GarageVehicles.Find(vehicle => vehicle.CarId == character.ActiveVehicleId);
                character.Crew = CrewModel.Retrieve(dbconn, character.CrewId);
            }

            return(chars);
        }
Exemplo n.º 2
0
        public static Character Retrieve(MySqlConnection dbconn, ulong cid)
        {
            var command = new MySqlCommand(
                "SELECT * FROM Characters WHERE characters.CID = @cid", dbconn);

            command.Parameters.AddWithValue("@cid", cid);

            Character character;

            using (DbDataReader reader = command.ExecuteReader())
            {
                if (!reader.Read())
                {
                    return(null);
                }
                character = GetCharacter(dbconn, reader);
            }
            character.GarageVehicles = VehicleModel.Retrieve(dbconn, character.Id);
            character.ActiveCar      = character.GarageVehicles.Find(vehicle => vehicle.CarId == character.ActiveVehicleId);
            character.Crew           = CrewModel.Retrieve(dbconn, character.CrewId);
            return(character);
        }