Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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));
        }