Ejemplo n.º 1
0
        public static List <UserForProfile> getUsersByName(SqlConnection sqlConnection, string username)
        {
            sqlConnection.Close();

            SqlCommand cmd = new SqlCommand(DBUtils.getUsersByNameCommand, sqlConnection);

            cmd.Parameters.AddWithValue(nameWithAt(USERS_COLUMN_NAME), "%" + username + "%");
            sqlConnection.Open();

            List <UserForProfile> users = new List <UserForProfile>();

            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    UserForProfile user = new UserForProfile();
                    user.Id       = reader.GetInt32(0);
                    user.UserName = reader.GetString(1);
                    user.Mail     = reader.GetString(2);
                    if (!reader.IsDBNull(3))
                    {
                        user.City = reader.GetString(3);
                    }
                    if (!reader.IsDBNull(4))
                    {
                        user.VehicleMake = reader.GetString(4);
                    }
                    if (!reader.IsDBNull(5))
                    {
                        user.VehicleModel = reader.GetString(5);
                    }
                    if (!reader.IsDBNull(6))
                    {
                        user.Birthdate = reader.GetDateTime(6).ToShortDateString();
                    }

                    users.Add(user);
                }
            }
            sqlConnection.Close();

            return(users);
        }
Ejemplo n.º 2
0
        public static UserForProfile getUserForProfile(SqlConnection sqlConnection, int id)
        {
            sqlConnection.Close();

            SqlCommand cmd = new SqlCommand(DBUtils.getUserCommand, sqlConnection);

            cmd.Parameters.AddWithValue(nameWithAt(USERS_COLUMN_ID), id);
            sqlConnection.Open();

            UserForProfile user = null;

            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                if (reader.Read())
                {
                    user          = new UserForProfile();
                    user.Id       = reader.GetInt32(0);
                    user.UserName = reader.GetString(1);
                    user.Mail     = reader.GetString(3);
                    if (!reader.IsDBNull(4))
                    {
                        user.City = reader.GetString(4);
                    }
                    if (!reader.IsDBNull(7))
                    {
                        user.VehicleMake = reader.GetString(7);
                    }
                    if (!reader.IsDBNull(8))
                    {
                        user.VehicleModel = reader.GetString(8);
                    }
                    if (!reader.IsDBNull(9))
                    {
                        user.Birthdate = reader.GetDateTime(9).ToShortDateString();
                    }
                }
            }
            sqlConnection.Close();

            return(user);
        }