protected void PrepareNewsItemModel(NewsItemModel model, NewsItem newsItem, bool prepareComments) { if (newsItem == null) throw new ArgumentNullException("newsItem"); if (model == null) throw new ArgumentNullException("model"); model.Id = newsItem.Id; model.SeName = newsItem.GetSeName(); model.Title = newsItem.Title; model.Short = newsItem.Short; model.Full = newsItem.Full; model.AllowComments = newsItem.AllowComments; model.CreatedOn = _dateTimeHelper.ConvertToUserTime(newsItem.CreatedOnUtc, DateTimeKind.Utc); model.NumberOfComments = newsItem.NewsComments.Count; if (prepareComments) { var newsComments = newsItem.NewsComments.Where(pr => pr.IsApproved).OrderBy(pr => pr.CreatedOnUtc); foreach (var nc in newsComments) { var commentModel = new NewsCommentModel() { Id = nc.Id, CustomerId = nc.CustomerId, CustomerName = nc.Customer.FormatUserName(), CommentTitle = nc.CommentTitle, CommentText = nc.CommentText, CreatedOn = _dateTimeHelper.ConvertToUserTime(nc.CreatedOnUtc, DateTimeKind.Utc), AllowViewingProfiles = _customerSettings.AllowViewingProfiles && nc.Customer != null && !nc.Customer.IsGuest(), }; if (_customerSettings.AllowCustomersToUploadAvatars) { var customer = nc.Customer; string avatarUrl = _pictureService.GetPictureUrl(customer.GetAttribute<int>(SystemCustomerAttributeNames.AvatarPictureId), _mediaSettings.AvatarPictureSize, false); if (String.IsNullOrEmpty(avatarUrl) && _customerSettings.DefaultAvatarEnabled) avatarUrl = _pictureService.GetDefaultPictureUrl(_mediaSettings.AvatarPictureSize, PictureType.Avatar); commentModel.CustomerAvatarUrl = avatarUrl; } model.Comments.Add(commentModel); } } }
protected virtual void PrepareNewsItemModel(NewsItemModel model, NewsItem newsItem, bool prepareComments) { if (newsItem == null) throw new ArgumentNullException("newsItem"); if (model == null) throw new ArgumentNullException("model"); model.Id = newsItem.Id; model.MetaTitle = newsItem.MetaTitle; model.MetaDescription = newsItem.MetaDescription; model.MetaKeywords = newsItem.MetaKeywords; model.SeName = newsItem.GetSeName(newsItem.LanguageId, ensureTwoPublishedLanguages: false); model.Title = newsItem.Title; model.Short = newsItem.Short; model.Full = newsItem.Full; model.AllowComments = newsItem.AllowComments; model.CreatedOn = _dateTimeHelper.ConvertToUserTime(newsItem.CreatedOnUtc, DateTimeKind.Utc); model.NumberOfComments = newsItem.CommentCount; model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnNewsCommentPage; if (prepareComments) { var newsComments = newsItem.NewsComments.OrderBy(pr => pr.CreatedOnUtc); foreach (var nc in newsComments) { var commentModel = new NewsCommentModel() { Id = nc.Id, CustomerId = nc.CustomerId, CustomerName = nc.Customer.FormatUserName(), CommentTitle = nc.CommentTitle, CommentText = nc.CommentText, CreatedOn = _dateTimeHelper.ConvertToUserTime(nc.CreatedOnUtc, DateTimeKind.Utc), AllowViewingProfiles = _customerSettings.AllowViewingProfiles && nc.Customer != null && !nc.Customer.IsGuest(), }; if (_customerSettings.AllowCustomersToUploadAvatars) { commentModel.CustomerAvatarUrl = _pictureService.GetPictureUrl( nc.Customer.GetAttribute<int>(SystemCustomerAttributeNames.AvatarPictureId), _mediaSettings.AvatarPictureSize, _customerSettings.DefaultAvatarEnabled, defaultPictureType:PictureType.Avatar); } model.Comments.Add(commentModel); } } }
protected virtual void PrepareNewsItemModel(NewsItemModel model, NewsItem newsItem, bool prepareComments, bool preparePictureModel = true, int? newsThumbPictureSize = null) { if (newsItem == null) throw new ArgumentNullException("newsItem"); if (model == null) throw new ArgumentNullException("model"); model.Id = newsItem.Id; model.MetaTitle = newsItem.MetaTitle; model.MetaDescription = newsItem.MetaDescription; model.MetaKeywords = newsItem.MetaKeywords; model.SeName = newsItem.GetSeName(newsItem.LanguageId, ensureTwoPublishedLanguages: false); model.Title = newsItem.Title; model.Short = newsItem.Short; model.Full = newsItem.Full; model.AllowComments = newsItem.AllowComments; model.CreatedOn = _dateTimeHelper.ConvertToUserTime(newsItem.CreatedOnUtc, DateTimeKind.Utc); model.NumberOfComments = newsItem.CommentCount; model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnNewsCommentPage; if(preparePictureModel) { #region Prepare news picture //If a size has been set in the view, we use it in priority int pictureSize = newsThumbPictureSize.HasValue ? newsThumbPictureSize.Value : _mediaSettings.NewsThumbPictureSize; //prepare picture model var defaultNewsPictureCacheKey = string.Format(ModelCacheEventConsumer.PRODUCT_DEFAULTPICTURE_MODEL_KEY, newsItem.Id, pictureSize, true, _workContext.WorkingLanguage.Id, _webHelper.IsCurrentConnectionSecured(), _storeContext.CurrentStore.Id); model.DefaultPictureModel = _cacheManager.Get(defaultNewsPictureCacheKey, () => { var picture = _pictureService.GetPicturesByNewsId(newsItem.Id, 1).FirstOrDefault(); var pictureModel = new PictureModel { ImageUrl = _pictureService.GetPictureUrl(picture, pictureSize), FullSizeImageUrl = _pictureService.GetPictureUrl(picture), Title = string.Format(_localizationService.GetResource("Media.News.ImageLinkTitleFormat"), model.Title), AlternateText = string.Format(_localizationService.GetResource("Media.News.ImageAlternateTextFormat"), model.Title) }; return pictureModel; }); #endregion } if (prepareComments) { var newsComments = newsItem.NewsComments.OrderBy(pr => pr.CreatedOnUtc); foreach (var nc in newsComments) { var commentModel = new NewsCommentModel { Id = nc.Id, CustomerId = nc.CustomerId, CustomerName = nc.Customer.FormatUserName(), CommentTitle = nc.CommentTitle, CommentText = nc.CommentText, CreatedOn = _dateTimeHelper.ConvertToUserTime(nc.CreatedOnUtc, DateTimeKind.Utc), AllowViewingProfiles = _customerSettings.AllowViewingProfiles && nc.Customer != null && !nc.Customer.IsGuest(), }; if (_customerSettings.AllowCustomersToUploadAvatars) { commentModel.CustomerAvatarUrl = _pictureService.GetPictureUrl( nc.Customer.GetAttribute<int>(SystemCustomerAttributeNames.AvatarPictureId), _mediaSettings.AvatarPictureSize, _customerSettings.DefaultAvatarEnabled, defaultPictureType:PictureType.Avatar); } model.Comments.Add(commentModel); } } }