Exemple #1
0
        /// <summary>
        /// Permanently delete the specified album from the data store, including any
        /// child albums, media objects, and metadata. This action cannot be undone.
        /// </summary>
        /// <param name="album">The <see cref="IAlbum"/> to delete from the data store.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="album" /> is null.</exception>
        public void Delete(IAlbum album)
        {
            if (album == null)
            {
                throw new ArgumentNullException("album");
            }

            // Get a list of this album and all its child albums. Then delete.
            var albumIds = new List <int> {
                album.Id
            };

            albumIds.AddRange(GetChildAlbumIds(album));

            var repo = new MetadataRepository(Context);

            foreach (var aDto in Where(a => albumIds.Contains(a.AlbumId), m => m.Metadata))
            {
                // We must explicitly delete the album metadata because we don't have a cascade
                // delete relation between them.
                foreach (var mDto in aDto.Metadata.ToList())
                {
                    repo.Delete(mDto);
                }

                // The media objects belonging to this album will be automatically deleted through
                // the cascade delete defined in the database.
                Delete(aDto);
            }

            Save();

            var tagRepo = new TagRepository(Context);

            tagRepo.DeleteUnusedTags();
        }
        public void Save(IGalleryObject mediaObject)
        {
            if (mediaObject == null)
            {
                throw new ArgumentNullException("mediaObject");
            }

            if (mediaObject.IsNew)
            {
                var moDto = new MediaObjectDto
                {
                    FKAlbumId          = mediaObject.Parent.Id,
                    ThumbnailFilename  = mediaObject.Thumbnail.FileName,
                    ThumbnailWidth     = mediaObject.Thumbnail.Width,
                    ThumbnailHeight    = mediaObject.Thumbnail.Height,
                    ThumbnailSizeKB    = mediaObject.Thumbnail.FileSizeKB,
                    OptimizedFilename  = mediaObject.Optimized.FileName,
                    OptimizedWidth     = mediaObject.Optimized.Width,
                    OptimizedHeight    = mediaObject.Optimized.Height,
                    OptimizedSizeKB    = mediaObject.Optimized.FileSizeKB,
                    OriginalFilename   = mediaObject.Original.FileName,
                    OriginalWidth      = mediaObject.Original.Width,
                    OriginalHeight     = mediaObject.Original.Height,
                    OriginalSizeKB     = mediaObject.Original.FileSizeKB,
                    ExternalHtmlSource = mediaObject.Original.ExternalHtmlSource,
                    ExternalType       = (mediaObject.Original.ExternalType == MimeTypeCategory.NotSet ? String.Empty : mediaObject.Original.ExternalType.ToString()),
                    Seq              = mediaObject.Sequence,
                    CreatedBy        = mediaObject.CreatedByUserName,
                    DateAdded        = mediaObject.DateAdded,
                    LastModifiedBy   = mediaObject.LastModifiedByUserName,
                    DateLastModified = mediaObject.DateLastModified,
                    IsPrivate        = mediaObject.IsPrivate
                };

                Add(moDto);
                Save();                 // Save now so we can get at the ID

                if (mediaObject.Id != moDto.MediaObjectId)
                {
                    mediaObject.Id = moDto.MediaObjectId;
                }

                // Insert metadata items, if any, into metadata table.
                var repo = new MetadataRepository(Context);                 // Don't put in using construct because we don't want our Context disposed
                repo.Save(mediaObject.MetadataItems);
            }
            else
            {
                MediaObjectDto moDto = Find(mediaObject.Id);

                if (moDto != null)
                {
                    moDto.FKAlbumId          = mediaObject.Parent.Id;
                    moDto.ThumbnailFilename  = mediaObject.Thumbnail.FileName;
                    moDto.ThumbnailWidth     = mediaObject.Thumbnail.Width;
                    moDto.ThumbnailHeight    = mediaObject.Thumbnail.Height;
                    moDto.ThumbnailSizeKB    = mediaObject.Thumbnail.FileSizeKB;
                    moDto.OptimizedFilename  = mediaObject.Optimized.FileName;
                    moDto.OptimizedWidth     = mediaObject.Optimized.Width;
                    moDto.OptimizedHeight    = mediaObject.Optimized.Height;
                    moDto.OptimizedSizeKB    = mediaObject.Optimized.FileSizeKB;
                    moDto.OriginalFilename   = mediaObject.Original.FileName;
                    moDto.OriginalWidth      = mediaObject.Original.Width;
                    moDto.OriginalHeight     = mediaObject.Original.Height;
                    moDto.OriginalSizeKB     = mediaObject.Original.FileSizeKB;
                    moDto.ExternalHtmlSource = mediaObject.Original.ExternalHtmlSource;
                    moDto.ExternalType       = (mediaObject.Original.ExternalType == MimeTypeCategory.NotSet ? String.Empty : mediaObject.Original.ExternalType.ToString());
                    moDto.Seq              = mediaObject.Sequence;
                    moDto.CreatedBy        = mediaObject.CreatedByUserName;
                    moDto.DateAdded        = mediaObject.DateAdded;
                    moDto.LastModifiedBy   = mediaObject.LastModifiedByUserName;
                    moDto.DateLastModified = mediaObject.DateLastModified;
                    moDto.IsPrivate        = mediaObject.IsPrivate;

                    Save();

                    // Update metadata items, if necessary, in metadata table.
                    var repo = new MetadataRepository(Context);                     // Don't put in using construct because we don't want our Context disposed
                    repo.Save(mediaObject.MetadataItems);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Persist the specified album to the data store. Return the ID of the album.
        /// </summary>
        /// <param name="album">An instance of <see cref="IAlbum"/> to persist to the data store.</param>
        /// <returns>
        /// Return the ID of the album. If this is a new album and a new ID has been
        /// assigned, then this value has also been assigned to the ID property of the object.
        /// </returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="album" /> is null.</exception>
        public void Save(IAlbum album)
        {
            if (album == null)
            {
                throw new ArgumentNullException("album");
            }

            if (album.IsNew)
            {
                var aDto = new AlbumDto
                {
                    FKGalleryId            = album.GalleryId,
                    FKAlbumParentId        = (album.Parent.Id > 0 ? album.Parent.Id : new int?()),
                    DirectoryName          = album.DirectoryName,
                    ThumbnailMediaObjectId = album.Thumbnail.MediaObjectId,
                    SortByMetaName         = album.SortByMetaName,
                    SortAscending          = album.SortAscending,
                    Seq              = album.Sequence,
                    DateStart        = (album.DateStart > DateTime.MinValue ? album.DateStart : (DateTime?)null),
                    DateEnd          = (album.DateEnd > DateTime.MinValue ? album.DateEnd : (DateTime?)null),
                    CreatedBy        = album.CreatedByUserName,
                    DateAdded        = album.DateAdded,
                    LastModifiedBy   = album.LastModifiedByUserName,
                    DateLastModified = album.DateLastModified,
                    OwnedBy          = album.OwnerUserName,
                    OwnerRoleName    = album.OwnerRoleName,
                    IsPrivate        = album.IsPrivate
                };

                Add(aDto);
                Save();

                if (album.Id != aDto.AlbumId)
                {
                    album.Id = aDto.AlbumId;
                }

                // Insert metadata items, if any, into metadata table.
                var repo = new MetadataRepository(Context);                 // Don't put in using construct because we don't want our Context disposed
                repo.Save(album.MetadataItems);
            }
            else
            {
                AlbumDto aDto = Find(album.Id);

                if (aDto != null)
                {
                    aDto.FKGalleryId            = album.GalleryId;
                    aDto.FKAlbumParentId        = (album.Parent.Id > 0 ? album.Parent.Id : new int?());
                    aDto.DirectoryName          = album.DirectoryName;
                    aDto.ThumbnailMediaObjectId = album.ThumbnailMediaObjectId;
                    aDto.SortByMetaName         = album.SortByMetaName;
                    aDto.SortAscending          = album.SortAscending;
                    aDto.Seq              = album.Sequence;
                    aDto.DateStart        = (album.DateStart > DateTime.MinValue ? album.DateStart : (DateTime?)null);
                    aDto.DateEnd          = (album.DateEnd > DateTime.MinValue ? album.DateEnd : (DateTime?)null);
                    aDto.LastModifiedBy   = album.LastModifiedByUserName;
                    aDto.DateLastModified = album.DateLastModified;
                    aDto.OwnedBy          = album.OwnerUserName;
                    aDto.OwnerRoleName    = album.OwnerRoleName;
                    aDto.IsPrivate        = album.IsPrivate;

                    Save();

                    // Update metadata items, if necessary, in metadata table.
                    var repo = new MetadataRepository(Context);                     // Don't put in using construct because we don't want our Context disposed
                    repo.Save(album.MetadataItems);
                }
            }
        }