Пример #1
0
        /// <summary>
        /// Reorders the lightbox asset in the list with the new order number.
        /// </summary>
        public void ReorderLightboxAsset(int lightboxId, int assetId, int newOrderIndex)
        {
            LightboxAssetFinder finder = new LightboxAssetFinder {
                LightboxId = lightboxId
            };
            EntityList <LightboxAsset> lbAssets = LightboxAsset.FindMany(finder);

            //get sorted list of lightbox assets
            var sortedList = (from lba in lbAssets orderby lba.OrderNumber.GetValueOrDefault(9999), lba.LightboxAssetId select lba).ToList();

            //make sure newOrderIndex is within the list's bounds
            if (newOrderIndex >= sortedList.Count())
            {
                newOrderIndex = (sortedList.Count() - 1);
            }
            else if (newOrderIndex < 0)
            {
                newOrderIndex = 0;
            }

            //re-insert item into correct place within the sorted list
            int iCurrentIndex = sortedList.FindIndex(lba => lba.AssetId == assetId);

            if (iCurrentIndex >= 0) //check asset was found
            {
                LightboxAsset lightboxAsset = sortedList[iCurrentIndex];
                sortedList.RemoveAt(iCurrentIndex);
                sortedList.Insert(newOrderIndex, lightboxAsset);

                //update lightbox assets with their new positions
                for (int i = 0; i < sortedList.Count(); i++)
                {
                    LightboxAsset lba = sortedList[i];
                    lba.OrderNumber = i;
                    LightboxAsset.Update(lba);
                }
            }
        }
        public override void ProcessRequest()
        {
            if (!SessionInfo.Current.User.IsNull)
            {
                //if valid user then process request
                //using normal AssetFileHandler
                base.ProcessRequest();
            }
            else
            {
                // Get querystring values
                int            assetId          = GetIdFromFilename();
                int            assetImageSizeId = WebUtils.GetIntRequestParam("assetImageSizeId", 0);
                DownloadFormat downloadFormat   = GeneralUtils.ParseEnum(WebUtils.GetRequestParam("AssetImageFormat"), DownloadFormat.Original);
                bool           original         = (WebUtils.GetIntRequestParam("original", 0) == 1);
                int            lightboxSentId   = WebUtils.GetIntRequestParam("lsid", 0);
                int            senderId         = WebUtils.GetIntRequestParam("suid", 0);
                string         ticks            = WebUtils.GetRequestParam("dst", string.Empty);

                // Ensure asset id is specified
                if (assetId == 0 || lightboxSentId == 0)
                {
                    InvalidRequest();
                    return;
                }


                // Get the lightbox
                LightboxSent lightboxSent = LightboxSent.Get(lightboxSentId);

                //check that it's a valid lightboxsent object
                if (lightboxSent.IsNull)
                {
                    InvalidRequest();
                    return;
                }


                // Check posted data - ensure that the sender id and ticks match (ie. to ensure user is not messing with the querystring)
                if (!lightboxSent.SenderId.Equals(senderId) || ticks.Length < 6 || !lightboxSent.DateSent.Ticks.ToString().Substring(0, 6).Equals(ticks.Substring(0, 6)))
                {
                    InvalidRequest();
                    return;
                }


                // Make sure sender is a super user
                if (lightboxSent.Sender.UserRole != UserRole.SuperAdministrator)
                {
                    InvalidRequest();
                    return;
                }


                //verify that lightbox has download links enabled
                if (!lightboxSent.DownloadLinks.GetValueOrDefault(false))
                {
                    InvalidRequest();
                    return;
                }


                //check that asset exists in the lightbox being sent
                LightboxAssetFinder finder = new LightboxAssetFinder {
                    LightboxId = lightboxSent.LightboxId, AssetId = assetId
                };
                LightboxAsset lightboxAsset = LightboxAsset.FindOne(finder);

                if (lightboxAsset.IsNull)
                {
                    InvalidRequest();
                    return;
                }


                // Get the asset file info
                AssetFileInfo info = new AssetFileInfo(lightboxAsset.Asset);

                // Ensure file exists
                if (!info.FileExists)
                {
                    InvalidRequest();
                    return;
                }

                // Asset file path
                string path = info.FilePath;

                // Always update the audit history for external downloads
                AuditLogManager.LogAssetAction(assetId, lightboxSent.Sender, AuditAssetAction.DownloadedAssetFile);
                AuditLogManager.LogUserAction(lightboxSent.Sender, AuditUserAction.DownloadAssetFromContactSheet, string.Format("Downloaded asset {0} via contact sheet, sent by: {1} download by: {2}", assetId, lightboxSent.Sender.FullName, lightboxSent.RecipientEmail));

                DownloadAsset(lightboxAsset.Asset, path, original, downloadFormat, assetImageSizeId);
            }
        }