コード例 #1
0
ファイル: UserRepository.cs プロジェクト: mono/mvcwrench
        public static User CreateUser(User user)
        {
            NpgsqlConnection conn = new NpgsqlConnection (conn_string);
            NpgsqlCommand comm = conn.CreateCommand ();

            // Add data to the User table
            string sql = "INSERT INTO users (name, email) VALUES (@name, @email)";
            comm.CommandText = sql;

            comm.Parameters.Add ("@name", user.Name);
            comm.Parameters.Add ("@email", user.Email);

            conn.Open ();
            comm.ExecuteNonQuery ();
            comm.Dispose ();

            User new_user = GetUser (user.Name);

            // Add data to the OpenID table
            comm = conn.CreateCommand ();

            sql = "INSERT INTO openids (id, userid) VALUES (@id, @userid)";
            comm.CommandText = sql;

            comm.Parameters.Add ("@id", user.OpenID);
            comm.Parameters.Add ("@userid", new_user.ID);

            comm.ExecuteNonQuery ();

            comm.Dispose ();
            conn.Close ();

            return new_user;
        }
コード例 #2
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (User.Identity.IsAuthenticated) {
                User user = UserRepository.GetUser (User.Identity.Name);
                current_user = user;

                ViewData["CurrentUser"] = current_user;
            }

            base.OnActionExecuting (filterContext);
        }
コード例 #3
0
ファイル: UserRepository.cs プロジェクト: mono/mvcwrench
        public static void SaveUser(User user)
        {
            NpgsqlConnection conn = new NpgsqlConnection (conn_string);
            NpgsqlCommand comm = conn.CreateCommand ();

            // Add data to the User table
            string sql = "UPDATE users SET email = @email, gravatar = @gravatar, svn = @svn WHERE id = @id";
            comm.CommandText = sql;

            comm.Parameters.Add ("@id", user.ID);
            comm.Parameters.Add ("@svn", user.SvnAccount);
            comm.Parameters.Add ("@email", user.Email);
            comm.Parameters.Add ("@gravatar", user.Gravatar);

            conn.Open ();
            comm.ExecuteNonQuery ();
            comm.Dispose ();
        }
コード例 #4
0
ファイル: UserRepository.cs プロジェクト: mono/mvcwrench
        public static User GetUserFromSvn(string svn)
        {
            NpgsqlConnection conn = new NpgsqlConnection (conn_string);
            conn.Open ();

            NpgsqlCommand comm = conn.CreateCommand ();

            string sql = "SELECT * FROM users WHERE svn = @svn";
            comm.CommandText = sql;

            comm.Parameters.Add ("@svn", svn);

            NpgsqlDataReader reader = comm.ExecuteReader ();

            User user = null;

            while (reader.Read ())
                user = new User (reader);

            reader.Close ();
            comm.Dispose ();
            conn.Close ();

            return user;
        }