public GitHubAcc CreateRandomGithubAccount()
        {
            var    random = new RandomHelper();
            String uname  = random.RandomStr();
            var    g      = new GitHubAcc
            {
                Username  = uname,
                Id        = random.RandomInt(),
                Email     = uname + random.RandomEmail(),
                GitHubUrl = "http://github.com/" + uname
            };

            return(g);
        }
Exemplo n.º 2
0
        public static List <GitHubAcc> GetGitHubAccounts(SqlConnection conn)
        {
            string sql = "Select * from GithubAccounts";

            // Create command.
            SqlCommand cmd = new SqlCommand();

            // Set connection for Command.
            cmd.Connection  = conn;
            cmd.CommandText = sql;

            List <GitHubAcc> gitHubAccountList = new List <GitHubAcc>();

            using (DbDataReader reader = cmd.ExecuteReader())
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        int uidIndex = reader.GetOrdinal("userid");
                        int uid      = reader.GetInt32(uidIndex);

                        int    unameIndex = reader.GetOrdinal("username");
                        String uname      = reader.GetString(unameIndex);

                        int    emailIndex = reader.GetOrdinal("email");
                        String email      = reader.GetString(emailIndex);

                        int    urlIndex = reader.GetOrdinal("githuburl");
                        String url      = reader.GetString(urlIndex);

                        var gitHubAcc = new GitHubAcc();
                        gitHubAcc.Id        = uid;
                        gitHubAcc.Username  = uname;
                        gitHubAcc.Email     = email;
                        gitHubAcc.GitHubUrl = url;

                        gitHubAccountList.Add(gitHubAcc);

                        Console.WriteLine("username:" + uname);
                    }
                }
            }

            return(gitHubAccountList);
        }
Exemplo n.º 3
0
        private static void InsertGitHubAccount(SqlConnection conn, GitHubAcc gitHubAcc)
        {
            string sql = "Insert into GithubAccounts (userid, username, email, githuburl) "
                         + " values (@userid, @username, @email, @githuburl) ";

            SqlCommand cmd = conn.CreateCommand();

            cmd.CommandText = sql;


            cmd.Parameters.Add("@userid", SqlDbType.Int).Value        = gitHubAcc.Id;
            cmd.Parameters.Add("@username", SqlDbType.VarChar).Value  = gitHubAcc.Username;
            cmd.Parameters.Add("@email", SqlDbType.VarChar).Value     = gitHubAcc.Email;
            cmd.Parameters.Add("@githuburl", SqlDbType.VarChar).Value = gitHubAcc.GitHubUrl;

            int rowCount = cmd.ExecuteNonQuery();

            Console.WriteLine("Row Count affected = " + rowCount);
        }