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()); } } }
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); } }