public IActionResult Index(int page = 1) { if (page <= 1) { page = 1; } var list = _topicService.GetLastedList(page, 15); var model = new TopicListViewModel(); model.List = list.ReplaceTo(t => t.ToTopicListItemModel()); var lastReplyList = _replyService.GetLastByTopicIds(list.Select(t => t.Id).ToArray()); foreach (var item in model.List) { var reply = lastReplyList.FirstOrDefault(t => t.TopicId == item.Id); if (reply != null) { item.LastReply = reply.ToModel(); } } return(View(model)); }
public IViewComponentResult Invoke() { int count = 10; if (!User.Identity.IsAuthenticated) { return(Content("")); } var userId = User.Identity.GetUserId <int>(); var list = _topicService.GetLastedList(1, count, userId: userId); TopicListViewModel model = new TopicListViewModel(); model.List = list.ReplaceTo((s) => { return(s.ToTopicListItemModel()); }); return(View(model)); }