public Lightbox CreateLightbox(string name, bool isDefault) { Lightbox lb = Lightbox.New(); lb.UserId = User.UserId.GetValueOrDefault(); lb.Name = name; lb.IsDefault = false; lb.CreateDate = DateTime.Now; SaveLightbox(lb); if (isDefault) { SetDefaultLightbox(lb.LightboxId.GetValueOrDefault()); } AuditLogManager.LogUserAction(User, AuditUserAction.AddLightbox, string.Format("Created lightbox: {0} (LightboxId: {1})", lb.Name, lb.LightboxId)); return(lb); }
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 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"); } }