public virtual LastPostModel PrepareLastPost(ForumPost post, bool showTopic)
        {
            var model = new LastPostModel();

            if (post != null)
            {
                var forumTopic = _forumService.GetTopicById(post.TopicId);
                if (forumTopic != null)
                {
                    var customer = EngineContext.Current.Resolve <ICustomerService>().GetCustomerById(post.CustomerId);
                    model.Id                   = post.Id;
                    model.ForumTopicId         = post.TopicId;
                    model.ForumTopicSeName     = forumTopic.GetSeName();
                    model.ForumTopicSubject    = forumTopic.StripTopicSubject();
                    model.CustomerId           = post.CustomerId;
                    model.AllowViewingProfiles = _customerSettings.AllowViewingProfiles;
                    model.CustomerName         = customer.FormatUserName();
                    model.IsCustomerGuest      = customer.IsGuest();
                    //created on string
                    if (_forumSettings.RelativeDateTimeFormattingEnabled)
                    {
                        model.PostCreatedOnStr = post.CreatedOnUtc.ToString("f");
                    }
                    else
                    {
                        model.PostCreatedOnStr = _dateTimeHelper.ConvertToUserTime(post.CreatedOnUtc, DateTimeKind.Utc).ToString("f");
                    }
                }
            }
            model.ShowTopic = showTopic;
            return(model);
        }
Esempio n. 2
0
        /// <summary>
        /// Prepare the last post model
        /// </summary>
        /// <param name="forumPost">Forum post</param>
        /// <param name="showTopic">Whether to show topic</param>
        /// <returns>Last post model</returns>
        public virtual LastPostModel PrepareLastPostModel(ForumPost forumPost, bool showTopic)
        {
            var model = new LastPostModel();

            model.ShowTopic = showTopic;

            //do not throw an exception here
            if (forumPost == null)
            {
                return(model);
            }

            model.Id                   = forumPost.Id;
            model.ForumTopicId         = forumPost.TopicId;
            model.ForumTopicSeName     = forumPost.ForumTopic.GetSeName();
            model.ForumTopicSubject    = forumPost.ForumTopic.StripTopicSubject();
            model.CustomerId           = forumPost.CustomerId;
            model.AllowViewingProfiles = _customerSettings.AllowViewingProfiles && !forumPost.Customer.IsGuest();
            model.CustomerName         = forumPost.Customer.FormatUserName();
            //created on string
            if (_forumSettings.RelativeDateTimeFormattingEnabled)
            {
                model.PostCreatedOnStr = forumPost.CreatedOnUtc.RelativeFormat(true, "f");
            }
            else
            {
                model.PostCreatedOnStr = _dateTimeHelper.ConvertToUserTime(forumPost.CreatedOnUtc, DateTimeKind.Utc).ToString("f");
            }

            return(model);
        }
Esempio n. 3
0
        /// <summary>
        /// Prepare the last post model
        /// </summary>
        /// <param name="forumPost">Forum post</param>
        /// <param name="showTopic">Whether to show topic</param>
        /// <returns>Last post model</returns>
        public virtual LastPostModel PrepareLastPostModel(ForumPost forumPost, bool showTopic)
        {
            var model = new LastPostModel
            {
                ShowTopic = showTopic
            };

            //do not throw an exception here
            if (forumPost == null)
            {
                return(model);
            }

            model.Id                   = forumPost.Id;
            model.ForumTopicId         = forumPost.TopicId;
            model.ForumTopicSeName     = _forumService.GetTopicSeName(forumPost.ForumTopic);
            model.ForumTopicSubject    = _forumService.StripTopicSubject(forumPost.ForumTopic);
            model.CustomerId           = forumPost.CustomerId;
            model.AllowViewingProfiles = _customerSettings.AllowViewingProfiles && !forumPost.Customer.IsGuest();
            model.CustomerName         = _customerService.FormatUserName(forumPost.Customer);
            //created on string
            var languageCode = _workContext.WorkingLanguage.LanguageCulture;

            if (_forumSettings.RelativeDateTimeFormattingEnabled)
            {
                var postCreatedAgo = forumPost.CreatedOnUtc.RelativeFormat(languageCode);
                model.PostCreatedOnStr = string.Format(_localizationService.GetResource("Common.RelativeDateTime.Past"), postCreatedAgo);
            }
            else
            {
                model.PostCreatedOnStr = _dateTimeHelper.ConvertToUserTime(forumPost.CreatedOnUtc, DateTimeKind.Utc).ToString("f");
            }

            return(model);
        }
Esempio n. 4
0
        public ActionResult LastPost(int forumPostId, bool showTopic)
        {
            var post  = _forumService.GetPostById(forumPostId);
            var model = new LastPostModel();

            if (post != null)
            {
                model.Id                   = post.Id;
                model.ForumTopicId         = post.TopicId;
                model.ForumTopicSeName     = post.ForumTopic.GetSeName();
                model.ForumTopicSubject    = post.ForumTopic.StripTopicSubject();
                model.CustomerId           = post.CustomerId;
                model.AllowViewingProfiles = _customerSettings.AllowViewingProfiles;
                model.CustomerName         = post.Customer.FormatUserName();
                model.IsCustomerGuest      = post.Customer.IsGuest();
                //created on string
                if (_forumSettings.RelativeDateTimeFormattingEnabled)
                {
                    model.PostCreatedOnStr = post.CreatedOnUtc.RelativeFormat(true, "f");
                }
                else
                {
                    model.PostCreatedOnStr = _dateTimeHelper.ConvertToUserTime(post.CreatedOnUtc, DateTimeKind.Utc).ToString("f");
                }
            }
            model.ShowTopic = showTopic;
            return(PartialView(model));
        }
Esempio n. 5
0
        /// <summary>
        /// Prepare the last post model
        /// </summary>
        /// <param name="forumPost">Forum post</param>
        /// <param name="showTopic">Whether to show topic</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the last post model
        /// </returns>
        public virtual async Task <LastPostModel> PrepareLastPostModelAsync(ForumPost forumPost, bool showTopic)
        {
            var model = new LastPostModel
            {
                ShowTopic = showTopic
            };

            //do not throw an exception here
            if (forumPost == null)
            {
                return(model);
            }

            var topic = await _forumService.GetTopicByIdAsync(forumPost.TopicId);

            if (topic is null)
            {
                return(model);
            }

            var customer = await _customerService.GetCustomerByIdAsync(forumPost.CustomerId);

            model.Id               = forumPost.Id;
            model.ForumTopicId     = topic.Id;
            model.ForumTopicSeName = await _forumService.GetTopicSeNameAsync(topic);

            model.ForumTopicSubject    = _forumService.StripTopicSubject(topic);
            model.CustomerId           = forumPost.CustomerId;
            model.AllowViewingProfiles = _customerSettings.AllowViewingProfiles && !await _customerService.IsGuestAsync(customer);

            model.CustomerName = await _customerService.FormatUsernameAsync(customer);

            //created on string
            var languageCode = (await _workContext.GetWorkingLanguageAsync()).LanguageCulture;

            if (_forumSettings.RelativeDateTimeFormattingEnabled)
            {
                var postCreatedAgo = forumPost.CreatedOnUtc.RelativeFormat(languageCode);
                model.PostCreatedOnStr = string.Format(await _localizationService.GetResourceAsync("Common.RelativeDateTime.Past"), postCreatedAgo);
            }
            else
            {
                model.PostCreatedOnStr = (await _dateTimeHelper.ConvertToUserTimeAsync(forumPost.CreatedOnUtc, DateTimeKind.Utc)).ToString("f");
            }

            return(model);
        }
Esempio n. 6
0
        public virtual async Task <LastPostModel> PrepareLastPost(string forumPostId, bool showTopic)
        {
            var post = await _forumService.GetPostById(forumPostId);

            var model = new LastPostModel();

            if (post != null)
            {
                var forumTopic = await _forumService.GetTopicById(post.TopicId);

                if (forumTopic != null)
                {
                    var customer = await _serviceProvider.GetRequiredService <ICustomerService>().GetCustomerById(post.CustomerId);

                    model.Id                   = post.Id;
                    model.ForumTopicId         = post.TopicId;
                    model.ForumTopicSeName     = forumTopic.GetSeName();
                    model.ForumTopicSubject    = forumTopic.StripTopicSubject(_forumSettings);
                    model.CustomerId           = post.CustomerId;
                    model.AllowViewingProfiles = _customerSettings.AllowViewingProfiles;
                    model.CustomerName         = customer.FormatUserName(_customerSettings.CustomerNameFormat);
                    model.IsCustomerGuest      = customer.IsGuest();
                    //created on string
                    if (_forumSettings.RelativeDateTimeFormattingEnabled)
                    {
                        model.PostCreatedOnStr = post.CreatedOnUtc.ToString("f");
                    }
                    else
                    {
                        model.PostCreatedOnStr = _dateTimeHelper.ConvertToUserTime(post.CreatedOnUtc, DateTimeKind.Utc).ToString("f");
                    }
                }
            }
            model.ShowTopic = showTopic;
            return(model);
        }