/// <summary> /// Updates the data store records with the values of this instance. /// </summary> private void SaveExisting() { if (MimeTypeId == int.MinValue) { throw new InvalidOperationException("Cannot call SaveExisting for new MIME types."); } using (var repo = new MimeTypeRepository()) { var mtDto = repo.Find(MimeTypeId); if (mtDto != null && mtDto.MimeTypeValue != FullType) { mtDto.MimeTypeValue = FullType; repo.Save(); } } using (var repo = new MimeTypeGalleryRepository()) { var mtDto = repo.Find(MimeTypeGalleryId); if (mtDto != null && mtDto.IsEnabled != AllowAddToGallery) { mtDto.IsEnabled = AllowAddToGallery; repo.Save(); } } }
/// <summary> /// Persist the gallery-specific properties of this instance to the data store. Currently, only the <see cref="IMimeType.AllowAddToGallery" /> /// property is unique to the gallery identified in <see cref="IMimeType.GalleryId" />; the other properties are application-wide and at /// present there is no API to modify them. In other words, this method saves whether a particular MIME type is enabled or disabled for a /// particular gallery. /// </summary> /// <exception cref="InvalidOperationException">Thrown when the current instance is an application-level MIME type. Only gallery-specific /// MIME types can be persisted to the data store. Specifically, the exception is thrown when <see cref="IMimeType.GalleryId" /> or /// <see cref="IMimeType.MimeTypeGalleryId" /> is <see cref="Int32.MinValue" />.</exception> public void Save() { if ((GalleryId == int.MinValue) || (MimeTypeGalleryId == int.MinValue)) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "Cannot save. This MIME type instance is an application-level MIME type and cannot be persisted to the data store. Only gallery-specific MIME types can be saved. (GalleryId={0}, MimeTypeId={1}, MimeTypeGalleryId={2}, FileExtension={3}", GalleryId, MimeTypeId, MimeTypeGalleryId, Extension)); } //Factory.GetDataProvider().MimeType_Save(this); using (var repo = new MimeTypeGalleryRepository()) { var mtDto = repo.Find(MimeTypeGalleryId); if (mtDto != null) { mtDto.IsEnabled = AllowAddToGallery; repo.Save(); } } }