/// <summary> /// Deletes the specified media object. /// </summary> /// <param name="mediaObject">The media object.</param> public void Delete(IGalleryObject mediaObject) { var mDto = Find(mediaObject.Id); if (mDto != null) { Delete(mDto); Save(); // Cascade relationship will auto-delete metadata items } var tagRepo = new TagRepository(Context); tagRepo.DeleteUnusedTags(); }
/// <summary> /// Persists the tags, if applicable, to the data store. Applies to /// <see cref="MetadataItemName.Tags" /> and /// <see cref="MetadataItemName.People" />. /// </summary> /// <param name="metadataDto">An instance of <see cref="MetadataDto"/>.</param> /// <param name="galleryId"></param> private void SaveTags(MetadataDto metadataDto, int galleryId) { if ((metadataDto.MetaName != Business.Metadata.MetadataItemName.Tags) && (metadataDto.MetaName != Business.Metadata.MetadataItemName.People)) { return; } var tags = ParseTags(metadataDto.Value); var tagRepo = new TagRepository(Context); // Don't put in using construct because we don't want our Context disposed tagRepo.Save(metadataDto.MetaName, tags); var metaTagRepo = new MetadataTagRepository(Context); // Don't put in using construct because we don't want our Context disposed metaTagRepo.Save(metadataDto, tags, galleryId); }
/// <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(); }