/// <summary> /// Create a new MimeType and MimeTypeGallery record for this instance. /// </summary> /// <exception cref="InvalidOperationException">Thrown when <see cref="MimeTypeId" /> is any value other than <see cref="Int32.MinValue" /></exception> private void SaveNew() { if (MimeTypeId != int.MinValue) { throw new InvalidOperationException("Cannot call SaveNew when the MIME type already exists in the data store."); } int mimeTypeId; using (var repo = new MimeTypeRepository()) { var mimeTypeDto = new MimeTypeDto() { FileExtension = Extension, MimeTypeValue = FullType, BrowserMimeTypeValue = BrowserMimeType }; repo.Add(mimeTypeDto); repo.Save(); mimeTypeId = mimeTypeDto.MimeTypeId; } using (var repo = new MimeTypeGalleryRepository()) { repo.Add(new MimeTypeGalleryDto() { FKGalleryId = GalleryId, FKMimeTypeId = mimeTypeId, IsEnabled = AllowAddToGallery }); repo.Save(); } // Clear the gallery cache. This will eventually trigger Gallery.Configure(), which will ensure that all galleries have a MimeTypeGallery record for // this MIME type. Factory.ClearGalleryCache(); }