jxycms
4/3/2017 - 4:32 AM

be used to get multiple attachments in page type

be used to get multiple attachments in page type

public string GalleryFirstTransformation(object nodeId)
{
    int nodeid = ValidationHelper.GetInteger(nodeId, 0);

    StringBuilder htmlOutput = new StringBuilder();
    if (!string.IsNullOrEmpty(nodeid.ToString()))
    {
        TreeProvider treeProvider = new TreeProvider(SiteContext.CurrentUser);
        TreeNode node = treeProvider.SelectSingleNode(nodeid);
        if (node != null)
        {
            Guid guidGallery = new Guid("043C279B-F5FC-4F05-947B-9A448878E77C");

            var attachmentModalGallery = AttachmentInfoProvider.GetAttachments()
               .WhereEquals("AttachmentDocumentId", node.DocumentID)
               .WhereEquals("AttachmentGroupGUID", guidGallery.ToString())
               .OrderBy("AttachmentOrder");
            if (attachmentModalGallery.Tables[0].Rows.Count != 0)
            {
                foreach (var attachment in attachmentModalGallery)
                {
                    var publishedAttachment = attachment as AttachmentInfo;
                    if (publishedAttachment == null) continue;
                    var imageurl = ResolveUrl(AttachmentInfoProvider.GetAttachmentUrl(publishedAttachment.AttachmentGUID, node.NodeAlias));
                    htmlOutput.Append("<div class='item'>");
                    htmlOutput.AppendFormat("<a data-gal='prettyPhoto[product]' href='{0}'>", imageurl);
                    htmlOutput.AppendFormat("<img alt='' src='{0}'>", imageurl);
                    htmlOutput.Append("</a>");
                    htmlOutput.Append(" </div>");
                }
            }
            else {
                TreeProvider tree = new TreeProvider(SiteContext.CurrentUser);
                TreeNode nodeImage = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/images/PlaceHolderImage/PlaceHolder", "en-au");
                var nodeImageUrl = ValidationHelper.GetString(nodeImage.GetValue("FileAttachment"), "");
                htmlOutput.Append("<div class='item'>");
                htmlOutput.AppendFormat("<a data-gal='prettyPhoto[product]' href='/CMSPages/GetFile.aspx?guid={0}'>", nodeImageUrl);
                htmlOutput.AppendFormat("<img alt='' src='/CMSPages/GetFile.aspx?guid={0}'>", nodeImageUrl);
                htmlOutput.Append("</a>");
                htmlOutput.Append(" </div>");
            }
            
        }
    }
    return htmlOutput.ToString();
}