예제 #1
0
        private void PrepareNewsItemListModel(NewsItemModel model, NewsItem newsItem, bool prepareComments, NewsItemPictureType newsItemPictureType, bool getCommentCount = true)
        {
            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.CreatedOn = _dateTimeHelper.ConvertToUserTime(newsItem.CreatedOnUtc, DateTimeKind.Utc);
            if (getCommentCount)
            {
                model.NumberOfComments = newsItem.NewsComments.Count;
            }
            model.SystemType = newsItem.SystemTypeId;
            model.Full       = newsItem.Full;
            //pictures
            var pictures = _newsService.GetNewsItemPicturesByNewsItemId(newsItem.Id, newsItemPictureType);

            if (pictures.Count > 0)
            {
                var picture     = pictures.FirstOrDefault();
                int pictureSize = 0;
                if (newsItemPictureType == NewsItemPictureType.Main)
                {
                    pictureSize = _mediaSettings.NewsItemPictureSize;
                }
                else if (newsItemPictureType == NewsItemPictureType.Thumb)
                {
                    pictureSize = _mediaSettings.NewsItemThumbPictureSize;
                }
                else
                {
                    pictureSize = _mediaSettings.NewsItemDetailPictureSize;
                }


                model.DefaultPictureModel = new PictureModel()
                {
                    //ImageUrl = _pictureService.GetPictureUrl(picture.PictureId, pictureSize),
                    ImageUrl         = _pictureService.GetPictureUrl(_newsService.GetMediaPictureByNewsItemPictureId(picture.PictureId), pictureSize),
                    FullSizeImageUrl = _pictureService.GetPictureUrl(_newsService.GetMediaPictureByNewsItemPictureId(picture.PictureId)),
                    //FullSizeImageUrl = _pictureService.GetPictureUrl(picture.PictureId),
                    Title         = string.Format(_localizationService.GetResource("Media.Product.ImageLinkTitleFormat"), model.Title),
                    AlternateText = string.Format(_localizationService.GetResource("Media.Product.ImageAlternateTextFormat"), model.Title),
                };
            }
            else
            {
                //no images. set the default one
                model.DefaultPictureModel = new PictureModel()
                {
                    ImageUrl         = _pictureService.GetDefaultPictureUrl(_mediaSettings.NewsItemThumbPictureSize),
                    FullSizeImageUrl = _pictureService.GetDefaultPictureUrl(),
                    Title            = string.Format(_localizationService.GetResource("Media.Product.ImageLinkTitleFormat"), model.Title),
                    AlternateText    = string.Format(_localizationService.GetResource("Media.Product.ImageAlternateTextFormat"), model.Title),
                };
            }
        }
예제 #2
0
        public List <dynamic> NewItemsBySystemType(int languageId, NewsType systemTypeId, int top, NewsItemPictureType newsItemPictureType = NewsItemPictureType.Standard)
        {
            string sql = @"select top(@top) News.Id NewsItemId, News.Url NewsItemUrl, News.MetaDescription NewsItemMetaDescription, Title, Short, SeName, Picture.Id PictureId, Picture.SeoFilename PictureSeoFilename
							from News, News_Picture_Mapping, Picture
							where LanguageId = @languageId and Published = 1 and SystemTypeId = @systemTypeId
							and News.Id = NewsItemId
							and News_Picture_Mapping.PictureId = Picture.Id
							and News_Picture_Mapping.DisplayOrder = 0
							and NewsItemPictureTypeId = @newsItemPictureType
							order by CreatedOnUtc desc"                            ;

            var mapped = _db.Query(sql, new { languageId = languageId, systemTypeId = systemTypeId, top = top, newsItemPictureType = newsItemPictureType });

            return(mapped.ToList());
        }