public void RemoveAssetFromLightbox(int lightboxId, int assetId, string additionalNotes) { Lightbox lb = GetLightboxById(lightboxId); if (EntitySecurityManager.CanManageLightbox(User, lb)) { if (LightboxContainsAsset(lb, assetId)) { foreach (LightboxAsset lba in lb.GetLightboxAssetList()) { if (lba.AssetId == assetId) { LightboxAsset.Delete(lba.LightboxAssetId); AuditLogManager.LogAssetAction(assetId, User, AuditAssetAction.RemovedFromLightbox); string notes = string.Format("Removed AssetId: {0} from LightboxId: {1}", assetId, lightboxId); if (!StringUtils.IsBlank(additionalNotes)) { notes += string.Format(". {0}", additionalNotes); } AuditLogManager.LogUserAction(User, AuditUserAction.RemoveFromLightbox, notes); } } } } else { m_Logger.DebugFormat("User: {0} (UserId: {1}) tried to remove AssetId: {2} from LightboxId: {3} but couldn't due to insufficient permissions to manage ths lightbox", User.FullName, User.UserId, assetId, lightboxId); } }
/// <summary> /// Adds a copy of the lightbox asset to the lightbox, if it does not contain the asset /// </summary> public void AddAssetToLightbox(Lightbox lightbox, LightboxAsset lightboxAsset) { if (!lightbox.IsNull && !lightboxAsset.IsNull) { if (EntitySecurityManager.CanManageLightbox(User, lightbox)) { if (!LightboxContainsAsset(lightbox, lightboxAsset.AssetId)) { LightboxAsset lba = LightboxAsset.New(); lba.LightboxId = lightbox.LightboxId.GetValueOrDefault(); lba.AssetId = lightboxAsset.AssetId; lba.Notes = lightboxAsset.Notes; lba.CreateDate = DateTime.Now; LightboxAsset.Update(lba); AuditLogManager.LogAssetAction(lightboxAsset.AssetId, User, AuditAssetAction.AddedToLightbox); AuditLogManager.LogUserAction(User, AuditUserAction.AddToLightbox, string.Format("Added AssetId: {0} to LightboxId: {1}", lightboxAsset.AssetId, lightbox.LightboxId.GetValueOrDefault())); } } else { m_Logger.DebugFormat("User: {0} (UserId: {1}) tried to add AssetId: {2} to LightboxId: {3} but couldn't due to insufficient permissions to manage ths lightbox", User.FullName, User.UserId, lightboxAsset.AssetId, lightbox.LightboxId.GetValueOrDefault()); } } }
/// <summary> /// creates a new lightbox asset and adds this to the lightbox with the specified ID, if it does not contain it already /// </summary> public void AddAssetToLightbox(int lightboxId, int assetId) { LightboxAsset lba = LightboxAsset.New(); lba.LightboxId = lightboxId; lba.AssetId = assetId; AddAssetToLightbox(lightboxId, lba); }
protected void LightboxDataList_ItemDataBound(object sender, DataListItemEventArgs e) { switch (e.Item.ItemType) { case (ListItemType.Item): case (ListItemType.AlternatingItem): Panel LightboxAssetInfoPanel = (Panel)e.Item.FindControl("LightboxAssetInfoPanel"); LightboxAsset lightboxAsset = (LightboxAsset)e.Item.DataItem; if (lightboxAsset.IsNull) { LightboxAssetInfoPanel.Visible = false; // Clear the CSS class so the background doesnt show WebControl wc = (WebControl)LightboxAssetInfoPanel.Parent; wc.CssClass = string.Empty; } else { Asset asset = lightboxAsset.Asset; AssetThumbnail AssetThumbnail1 = (AssetThumbnail)e.Item.FindControl("AssetThumbnail1"); HtmlGenericControl AssetIdLabel = (HtmlGenericControl)e.Item.FindControl("AssetIdLabel"); HtmlGenericControl AssetTypeLabel = (HtmlGenericControl)e.Item.FindControl("AssetTypeLabel"); Image NotesImage = (Image)e.Item.FindControl("NotesImage"); HyperLink DownloadHyperLink = (HyperLink)e.Item.FindControl("DownloadHyperLink"); AssetThumbnail1.HoverCaption = asset.Title; AssetThumbnail1.HoverText = GeneralUtils.GetNonEmptyString(lightboxAsset.Notes, "[Sender has not entered any notes]"); AssetThumbnail1.Initialise(asset); AssetIdLabel.InnerText = asset.AssetId.ToString(); AssetTypeLabel.InnerText = "(" + asset.AssetType.Name + ")"; NotesImage.AlternateText = Server.HtmlEncode(AssetThumbnail1.HoverText); NotesImage.ToolTip = Server.HtmlEncode(AssetThumbnail1.HoverText); //check if light box was sent with download links enabled //and double check that the sender was super admin if (m_lightboxSent.DownloadLinks.GetValueOrDefault(false) && m_lightboxSent.Sender.UserRole == UserRole.SuperAdministrator) { DownloadHyperLink.Visible = true; DownloadHyperLink.NavigateUrl = AssetFileUrlHelper.GetExternalDownloadUrl(asset.AssetId, m_lightboxSent.LightboxSentId, m_lightboxSent.SenderId, m_lightboxSent.DateSent.Ticks); DownloadHyperLink.ImageUrl = SiteUtils.GetIconPath("download0.gif"); } else { DownloadHyperLink.Visible = false; } } break; } }
protected void AssetRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { switch (e.Item.ItemType) { case (ListItemType.Item): case (ListItemType.AlternatingItem): Asset asset = Asset.Empty; if (e.Item.DataItem is Cart) { Cart cart = (Cart)e.Item.DataItem; asset = cart.Asset; } else if (e.Item.DataItem is LightboxAsset) { LightboxAsset lba = (LightboxAsset)e.Item.DataItem; asset = lba.Asset; } AssetThumbnail AssetThumbnail1 = (AssetThumbnail)e.Item.FindControl("AssetThumbnail1"); AssetButtons AssetButtons1 = (AssetButtons)e.Item.FindControl("AssetButtons1"); PlaceHolder AssetContainer = (PlaceHolder)e.Item.FindControl("AssetContainer"); PlaceHolder EmptyAssetContainer = (PlaceHolder)e.Item.FindControl("EmptyAssetContainer"); if (asset.IsNull) { AssetContainer.Visible = false; EmptyAssetContainer.Visible = true; } else { AssetContainer.Visible = true; EmptyAssetContainer.Visible = false; AssetButtons1.LightboxId = SelectedLightboxId; AssetThumbnail1.Initialise(asset); AssetButtons1.Initialise(asset); AssetButtons1.LightboxButtonClicked += new AssetButtonEventHandler(AssetButtons1_LightboxButtonClicked); AssetButtons1.CartButtonClicked += new AssetButtonEventHandler(AssetButtons1_CartButtonClicked); } break; } }
/// <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); } } }
private Lightbox DuplicateLightbox(int lightboxId, string newName, int targetUserId) { ValidateLightboxName(newName); if (IsDuplicateName(newName, targetUserId)) { string message = (targetUserId == User.UserId.GetValueOrDefault()) ? "A lightbox with that name already exists" : "User already has a lightbox with that name"; throw new InvalidLightboxException(message); } Lightbox lightbox = GetLightboxById(lightboxId); Lightbox newLightbox = Lightbox.New(); newLightbox.UserId = targetUserId; newLightbox.Name = newName; newLightbox.Summary = lightbox.Summary; newLightbox.Notes = lightbox.Notes; newLightbox.IsDefault = false; newLightbox.CreateDate = DateTime.Now; SaveLightbox(newLightbox); foreach (LightboxAsset lba in lightbox.GetLightboxAssetList()) { LightboxAsset newlba = LightboxAsset.New(); newlba.LightboxId = newLightbox.LightboxId.GetValueOrDefault(); newlba.AssetId = lba.AssetId; newlba.Notes = lba.Notes; newlba.CreateDate = DateTime.Now; LightboxAsset.Update(newlba); } return(newLightbox); }
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); } }
/// <summary> /// Adds a copy of the lightbox asset to the lightbox with the specified ID, if it does not contain the asset /// </summary> public void AddAssetToLightbox(int lightboxId, LightboxAsset lba) { Lightbox lb = GetLightboxById(lightboxId); AddAssetToLightbox(lb, lba); }