11@page " /"
2+ @page " /{Page:int}"
23@layout NoLayout
4+ @inject PostService PostService
35
46<div class =" jumbotron jumbotron-fluid" >
57 <div class =" container" >
1214<div class =" container" >
1315 <div class =" row" >
1416 <div class =" col-md-12" >
15- <!-- Post -->
16- <div class =" post" >
17- <div class =" user-block" >
18- <h1 >
19- <NavLink href =" /post/1" >This is post 1</NavLink >
20- </h1 >
21- <div >Created at 7:30 PM today</div >
17+ @foreach ( var post in Posts )
18+ {
19+ <!-- Post -->
20+ <div class =" post" >
21+ <div class =" user-block" >
22+ <h1 >
23+ <a href =" /post/@post.Id" >@post.Title </a >
24+ </h1 >
25+ <div >Created at @post.CreatedAt </div >
26+ </div >
27+ <!-- /.user-block -->
28+ <p >
29+ @post.Excerpt...
30+ </p >
31+ <p >
32+ @RenderTag(post.Id)
33+ </p >
34+ <p >
35+ <a href =" #" class =" link-black text-sm mr-2" ><i class =" fas fa-share mr-1" ></i > Share </a >
36+ <a href =" #" class =" link-black text-sm" ><i class =" far fa-thumbs-up mr-1" ></i > Like </a >
37+ <span class =" float-right" >
38+ <NavLink href =" #" class =" link-black text-sm" >
39+ <i class =" far fa-comments mr-1" ></i > Comments (5 )
40+ </NavLink >
41+ </span >
42+ </p >
2243 </div >
23- <!-- /.user-block -->
24- <p >
25- Lorem ipsum represents a long-held tradition for designers,
26- typographers and the like. Some people hate it and argue for
27- its demise, but others ignore the hate as they create awesome
28- tools to help create filler text for everyone from bacon lovers
29- to Charlie Sheen fans...
30- </p >
31-
32- <p >
33- <a href =" #" class =" link-black text-sm mr-2" ><i class =" fas fa-share mr-1" ></i > Share</a >
34- <a href =" #" class =" link-black text-sm" ><i class =" far fa-thumbs-up mr-1" ></i > Like</a >
35- <span class =" float-right" >
36- <NavLink href =" #" class =" link-black text-sm" >
37- <i class =" far fa-comments mr-1" ></i > Comments (5)
38- </NavLink >
39- </span >
40- </p >
41- </div >
42- <!-- /.post -->
43- <!-- Post -->
44- <div class =" post clearfix" >
45- <div class =" user-block" >
46- <h1 >
47- <NavLink href =" /post/2" >This is post 2</NavLink >
48- </h1 >
49- <div >Created at 3 days ago</div >
50- </div >
51- <!-- /.user-block -->
52- <p >
53- Lorem ipsum represents a long-held tradition for designers,
54- typographers and the like. Some people hate it and argue for
55- its demise, but others ignore the hate as they create awesome
56- tools to help create filler text for everyone from bacon lovers
57- to Charlie Sheen fans...
58- </p >
59-
60- <p >
61- <a href =" #" class =" link-black text-sm mr-2" ><i class =" fas fa-share mr-1" ></i > Share</a >
62- <a href =" #" class =" link-black text-sm" ><i class =" far fa-thumbs-up mr-1" ></i > Like</a >
63- <span class =" float-right" >
64- <NavLink href =" #" class =" link-black text-sm" >
65- <i class =" far fa-comments mr-1" ></i > Comments (5)
66- </NavLink >
67- </span >
68- </p >
69- </div >
70- <!-- /.post -->
44+ <!-- /.post -->
45+ }
7146 </div >
7247 </div >
7348</div >
8358</div >
8459
8560@code {
61+ [Parameter ] int Page { get ; set ; } = 1 ;
62+
63+ List <PostDto > Posts = new List <PostDto >();
64+ MapField <string , PostTagsDto > PostTags = new MapField <string , PostTagsDto >();
65+
66+ protected override async Task OnInitAsync ()
67+ {
68+ var resultModel = await PostService .GetPostsByBlog (Guid .NewGuid (), Page );
69+ Posts = resultModel .Data .Posts .ToList ();
70+ PostTags = resultModel .Data .TagFragment ;
71+ }
72+
73+ MarkupString RenderTag (string postId )
74+ {
75+ var result = PostTags
76+ .Where (x => x .Key == postId )
77+ .Select (x => x .Value )
78+ .SelectMany (x => x .Tags )
79+ .Select (x => x ? .Name )
80+ .Aggregate (" " , (r , x ) => r + string .Format (" <span class=\" badge badge-info\" >{0}</span>" , x ));
81+
82+ return (MarkupString )result ;
83+ }
8684}
0 commit comments