Beispiel #1
0
        public void RemoveLightbox(int lightboxId)
        {
            // Ensure that we have more than one lightbox
            if (UserLightboxes.Count == 1)
            {
                throw new InvalidLightboxException("cannot remove only lightbox");
            }

            // Get the lightbox
            Lightbox lb = GetLightboxById(lightboxId);

            // Default lightboxes cannot be removed
            if (lb.IsDefault)
            {
                throw new InvalidLightboxException("cannot remove default lightbox");
            }


            if (lb.IsLinked)
            {
                //remove linked lightbox
                LightboxLinked lightboxLinked = LightboxLinked.GetLightboxLinked(User.UserId.GetValueOrDefault(-1), lightboxId);

                if (!lightboxLinked.IsNull)
                {
                    LightboxLinked.Delete(lightboxLinked.LightboxLinkedId);
                }

                // Update audit log
                AuditLogManager.LogUserAction(User, AuditUserAction.RemoveLightbox, string.Format("Removed linked lightbox: {0} (LightboxLinkedId: {1})", lb.Name, lightboxLinked.LightboxLinkedId));
            }
            else
            {
                // Non-superadmins can only remove their own lightboxes
                if (User.UserRole != UserRole.SuperAdministrator && lb.UserId != User.UserId.GetValueOrDefault())
                {
                    throw new InvalidLightboxException("cannot remove lightbox not created by you");
                }

                // Delete it
                Lightbox.Delete(lb.LightboxId);

                // Update audit log
                AuditLogManager.LogUserAction(User, AuditUserAction.RemoveLightbox, string.Format("Removed lightbox: {0} (LightboxId: {1})", lb.Name, lb.LightboxId));
            }

            // Fire event
            OnLightboxListChanged();
        }
Beispiel #2
0
        private static bool IsLightboxLinked(int lightboxId, int userId)
        {
            LightboxLinked lightboxLinked = LightboxLinked.GetLightboxLinked(userId, lightboxId);

            return(!lightboxLinked.IsNull && lightboxLinked.ExpiryDate.GetValueOrDefault(DateTime.MaxValue) > DateTime.Now);
        }