Esempio n. 1
0
        /// <summary>
        /// Gets the default lightbox for the user.
        /// If the user does not have a default lightbox, but have lightboxes, the first lightbox
        /// will be made the default.  If the user has no lightboxes, returns a null lightbox
        /// </summary>
        public Lightbox GetDefaultLightbox()
        {
            // Try and find the default lightbox and return it
            foreach (Lightbox lb in UserLightboxes)
            {
                if (lb.IsDefault)
                {
                    return(lb);
                }
            }

            // Otherwise, there's no default lightbox, so
            // make the first one default that's not linked and return it
            if (UserLightboxes.Count > 0)
            {
                Lightbox lb = UserLightboxes.FirstOrDefault(l => l.IsLinked == false);

                if (lb != null)
                {
                    lb.IsDefault = true;
                    Lightbox.Update(lb);
                    return(lb);
                }
            }

            return(Lightbox.Empty);
        }
Esempio n. 2
0
        public void SaveLightbox(Lightbox lb)
        {
            ValidateLightboxName(lb.Name);

            if (lb.Summary.Length > 160)
            {
                throw new InvalidLightboxException("summary cannot exceed 160 characters");
            }

            if (lb.Notes.Length > 500)
            {
                throw new InvalidLightboxException("notes cannot exceed 500 characters");
            }

            if (lb.IsPublic && lb.Brands.Count == 0)
            {
                throw new InvalidLightboxException("public lightboxes must be assigned to at least one brand");
            }

            if (lb.CreateDate == DateTime.MinValue)
            {
                throw new InvalidLightboxException("system error - invalid createdate");
            }

            Lightbox.Update(lb);

            OnLightboxListChanged();
        }
Esempio n. 3
0
        public void SetDefaultLightbox(int lightboxId)
        {
            foreach (Lightbox lightbox in UserLightboxes)
            {
                if (!lightbox.IsLinked) //don't update linked lightboxes
                {
                    lightbox.IsDefault = (lightbox.LightboxId.GetValueOrDefault() == lightboxId);
                    Lightbox.Update(lightbox);
                }
            }

            OnLightboxListChanged();
        }
Esempio n. 4
0
        public static void EnsureUserHasDefaultLightbox(User user)
        {
            if (user.IsNew || user.IsNull)
            {
                return;
            }

            LightboxFinder finder = new LightboxFinder {
                UserId = user.UserId.GetValueOrDefault(), IsDefault = true
            };
            int count = Lightbox.GetCount(finder);

            if (count == 0)
            {
                Lightbox lb = Lightbox.New();
                lb.UserId     = user.UserId.GetValueOrDefault();
                lb.Name       = "My Assets";
                lb.IsDefault  = true;
                lb.CreateDate = DateTime.Now;
                Lightbox.Update(lb);

                AuditLogManager.LogUserAction(user, AuditUserAction.AddLightbox, "System created default lightbox as there were no other ligthboxes");
            }
        }