Exemplo n.º 1
0
        public ForumTableViewModel GetForumTableViewModelById(int forumId)
        {
            var forumTableViewModel = new ForumTableViewModel();

            try
            {
                List <ForumsViewEntity> forumViewEntities = _forumRepository.GetAllForums(_connectionFactory);
                var tempForumModels         = Mapper.Map <List <ForumsViewEntity>, List <ForumTableViewModel> >(forumViewEntities);
                var forumTableViewModelList = TransformToHierarchy(tempForumModels);

                forumTableViewModel           = GetFromHierarchyById(forumTableViewModelList, forumId);
                forumTableViewModel.SubForums = forumTableViewModel.SubForums.OrderBy(x => x.ForumOrder).ToList();
            }
            catch (Exception exception)
            {
                DemLogger.Current.Error(exception, $"{nameof(ForumReadService)}. Error in function {DemLogger.GetCallerInfo()}");
            }
            return(forumTableViewModel);
        }
Exemplo n.º 2
0
        private void FillSubForums(ForumTableViewModel root, List <ForumTableViewModel> forumModels)
        {
            try
            {
                foreach (ForumTableViewModel childNode in root.SubForums)
                {
                    childNode.SubForums = forumModels.Where(x => x.ParentId == childNode.ForumId).ToList();
                    if (childNode.SubForums.Count > 0)
                    {
                        FillSubForums(childNode, forumModels);
                    }
                }

                #region RefillLastPostData

                var latestDateTime = root.SubForums.Select(x => x.LastPostTime).Max();
                var lastForum      = root.SubForums.FirstOrDefault(x => x.LastPostTime == latestDateTime);
                if (lastForum != null && latestDateTime > root.LastPostTime)
                {
                    root.LastTopicTitle = lastForum.LastTopicTitle;
                    root.LastTopicId    = lastForum.LastTopicId;
                    root.LastPostTime   = lastForum.LastPostTime;
                    root.GroupColor     = lastForum.GroupColor;
                    root.Username       = lastForum.Username;
                }

                #endregion

                #region RecountTopicsAndPosts

                root.TopicsCount += root.SubForums.Select(x => x.TopicsCount).Sum();
                root.PostsCount  += root.SubForums.Select(x => x.PostsCount).Sum();

                #endregion
            }
            catch (Exception exception)
            {
                DemLogger.Current.Error(exception, $"{nameof(ForumReadService)}. Error in function {DemLogger.GetCallerInfo()}");
            }
        }