コード例 #1
0
        public int amountWeightPosts(string search)
        {
            List <WeightedPost> posts = new List <WeightedPost>();

            using (var db = new stackOverflowContext())
            {
                var conn = (MySqlConnection)db.Database.GetDbConnection();
                conn.Open();
                var cmd = new MySqlCommand();
                cmd.Connection = conn;

                cmd.Parameters.Add("@1", DbType.String);

                cmd.Parameters["@1"].Value = search;

                cmd.CommandText = "call subpj3_b4(@1)";

                var reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    WeightedPost post = new WeightedPost
                    {
                        postId = reader.GetInt32(0),
                    };
                    posts.Add(post);
                }
            }

            return(posts.Count());
        }
コード例 #2
0
        public List <WeightedPost> getWeightedPosts(string search, int page, int pageSize)
        {
            List <WeightedPost> posts = new List <WeightedPost>();

            using (var db = new stackOverflowContext())
            {
                var conn = (MySqlConnection)db.Database.GetDbConnection();
                conn.Open();
                var cmd = new MySqlCommand();
                cmd.Connection = conn;

                cmd.Parameters.Add("@1", DbType.String);

                cmd.Parameters["@1"].Value = search;

                cmd.CommandText = "call subpj3_b4(@1)";

                var reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    WeightedPost post = new WeightedPost
                    {
                        postId = reader.GetInt32(0),
                        title  = reader.GetString(1),
                        weight = reader.GetDouble(3)
                    };
                    posts.Add(post);
                }
            }

            List <WeightedPost> trimmedPostList = new List <WeightedPost>();

            for (int i = page * pageSize; i < (page * pageSize) + pageSize; i++)
            {
                if (i == posts.Count())
                {
                    break;
                }
                trimmedPostList.Add(posts[i]);
            }

            return(trimmedPostList);
        }