예제 #1
0
        public List <User> ListFriends(int id)
        {
            List <User> users = new List <User>();
            string      sql   = @"SELECT U.* FROM FRIENDS F INNER JOIN USERS U ON (F.FRIEND = U.ID) WHERE F.USER = ?";

            using (MySqlCommand command = new MySqlCommand(sql, connection))
            {
                command.Parameters.Add(@"USER", MySqlDbType.String).Value = id;
                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        User user = new User();
                        user.Id               = reader.GetInt32("ID");
                        user.Name             = reader.GetString("NAME");
                        user.Password         = reader.GetString("PASSWORD");
                        user.RegistrationDate = utilities.JulianToDate(reader.GetInt32("REGISTRATION_DATE"));
                        user.Email            = reader.GetString("EMAIL");
                        user.City             = reader.GetString("CITY");
                        user.Cpf              = reader.GetString("CPF");
                        user.BirthDate        = utilities.JulianToDate(reader.GetInt32("BIRTH_DATE"));
                        user.Genre            = reader.GetString("GENRE");
                        user.Description      = reader.GetString("DESCRIPTION");
                        user.ProfilePic       = reader.GetString("PROFILE_PIC");
                        user.CoverPic         = reader.GetString("COVER_PIC");
                        users.Add(user);
                    }
                }
            }
            return(users);
        }
예제 #2
0
        public User Login(string email, string password)
        {
            User   user = new User();
            string sql  = @"SELECT * FROM USERS WHERE EMAIL = ? AND PASSWORD = ?";

            using (MySqlCommand command = new MySqlCommand(sql, connection))
            {
                command.Parameters.Add(@"EMAIL", MySqlDbType.String).Value    = email;
                command.Parameters.Add(@"PASSWORD", MySqlDbType.String).Value = password;
                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        user.Id               = reader.GetInt32("ID");
                        user.Name             = reader.GetString("NAME");
                        user.Password         = reader.GetString("PASSWORD");
                        user.RegistrationDate = utilities.JulianToDate(reader.GetInt32("REGISTRATION_DATE"));
                        user.Email            = reader.GetString("EMAIL");
                        user.City             = reader.GetString("CITY");
                        user.Cpf              = reader.GetString("CPF");
                        user.BirthDate        = utilities.JulianToDate(reader.GetInt32("BIRTH_DATE"));
                        user.Genre            = reader.GetString("GENRE");
                        user.Description      = reader.GetString("DESCRIPTION");
                        user.ProfilePic       = reader.GetString("PROFILE_PIC");
                        user.CoverPic         = reader.GetString("COVER_PIC");
                    }
                }
            }
            return(user);
        }