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); } }
protected void Page_Load(object sender, EventArgs e) { // Get the data from the querystring, to be used to get the sent lightbox int lightboxSentId = WebUtils.GetIntRequestParam("lsid", 0); int senderId = WebUtils.GetIntRequestParam("suid", 0); string ticks = WebUtils.GetRequestParam("dst", string.Empty); // Ensure that we have all required querystring data if (lightboxSentId == 0 || senderId == 0 || ticks == string.Empty) { Response.Redirect("~/Login.aspx?error=ContactSheetMissingData", false); return; } // Get the lightbox m_lightboxSent = LightboxSent.Get(lightboxSentId); // Check posted data - ensure that the sender id and ticks match (ie. to ensure user is not messing with the querystring) if (!m_lightboxSent.SenderId.Equals(senderId) || ticks.Length < 6 || !m_lightboxSent.DateSent.Ticks.ToString().Substring(0, 6).Equals(ticks.Substring(0, 6))) { Response.Redirect("~/Login.aspx?error=ContactSheetInvalidData", false); return; } // Ensure the lightbox has not expired if (m_lightboxSent.ExpiryDate.HasValue && m_lightboxSent.ExpiryDate < DateTime.Now) { Response.Redirect("~/Login.aspx?error=ContactSheetExpired", false); return; } // Get the lightbox Lightbox lightbox = m_lightboxSent.Lightbox; // Update the UI with the lightbox information LightboxTitleLabel.Text = lightbox.Name; LightboxSenderName.Text = m_lightboxSent.Sender.FullName; LightboxSenderEmail.EmailAddress = m_lightboxSent.Sender.Email; LightboxDateSentLabel.Text = m_lightboxSent.DateSent.ToString("HH:mm, dd MMMM yyyy"); LightboxDateExpiresLabel.Text = m_lightboxSent.ExpiryDate.HasValue ? m_lightboxSent.ExpiryDate.Value.ToString("HH:mm, dd MMMM yyyy") : "Never"; LightboxNotesLabel.Text = lightbox.Notes; // Get the lightbox assets EntityList <LightboxAsset> lightboxAssetList = lightbox.GetLightboxAssetList(); // Ensure we have at least one row while (lightboxAssetList.Count < LightboxDataList.RepeatColumns) { lightboxAssetList.Add(LightboxAsset.Empty); } // Bind the datalist to the lightbox assets LightboxDataList.DataSource = lightboxAssetList; LightboxDataList.DataBind(); }
public void MergeLightbox(int sourceLightboxId, int targetLightboxId, bool removeSource) { if (sourceLightboxId == targetLightboxId) { throw new InvalidLightboxException("source and target lightbox cannot be the same"); } Lightbox source = GetLightboxById(sourceLightboxId); Lightbox target = GetLightboxById(targetLightboxId); if (source.IsLinked) { throw new InvalidLightboxException("cannot use linked lightboxes as the source"); } if (target.IsLinked) { throw new InvalidLightboxException("cannot use linked lightboxes as the target"); } if (removeSource) { if (source.IsDefault) { throw new InvalidLightboxException("source lightbox cannot removed as it is the default lightbox"); } if (!EntitySecurityManager.CanManageLightbox(User, source)) { throw new InvalidLightboxException("source lightbox cannot removed as you do not have permission"); } } foreach (LightboxAsset lba in source.GetLightboxAssetList()) { AddAssetToLightbox(targetLightboxId, lba); } if (removeSource) { RemoveLightbox(sourceLightboxId); } }
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 bool LightboxContainsAsset(Lightbox lightbox, int assetId) { return(lightbox.GetLightboxAssetList().Any(lba => lba.AssetId == assetId)); }