private void SaveSettings() { var mimeTypes = hdnMimeTypes.Value.FromJson <Entity.MimeType[]>(); // Loop through each MIME type entity. For each file extension, get the matching MIME type and add/edit/delete as needed. try { foreach (var mte in mimeTypes) { try { if (string.IsNullOrWhiteSpace(mte.Extension) || mte.Extension == ".") { throw new ArgumentException("No file extension was specified (e.g. .jpg, .mp4)."); } var hasChanges = false; var mimeType = Factory.LoadMimeType(GalleryId, mte.Extension); if (mimeType == null) { // User is adding a MIME type. var extension = mte.Extension.StartsWith(".") ? mte.Extension : string.Concat(".", mte.Extension); mimeType = MimeType.CreateInstance(MimeTypeCategory.NotSet, extension); mimeType.MimeTypeId = int.MinValue; mimeType.MimeTypeGalleryId = int.MinValue; mimeType.GalleryId = GalleryId; } if (mte.IsDeleted) { mimeType.Delete(); } else { if (mimeType.AllowAddToGallery != mte.Enabled) { mimeType.AllowAddToGallery = mte.Enabled; hasChanges = true; } if (mimeType.FullType != mte.FullType) { mimeType.FullType = mte.FullType; hasChanges = true; } if (hasChanges) { mimeType.Save(); } } } catch (Exception ex) { ex.Data.Add("FileExtension", mte.Extension); ex.Data.Add("MimeType", mte.FullType); throw; } } CacheController.RemoveCache(CacheItem.MimeTypes); CacheController.RemoveCache(CacheItem.InflatedAlbums); // Old MIME types might be in here, so we need to purge BindMimeTypes(); ClientMessage = new ClientMessageOptions { Title = Resources.GalleryServer.Admin_Save_Success_Hdr, Message = Resources.GalleryServer.Admin_Save_Success_Text, Style = MessageStyle.Success }; } catch (Exception ex) { EventController.RecordError(ex, AppSetting.Instance, GalleryId, Factory.LoadGallerySettings()); ClientMessage = new ClientMessageOptions { Title = Resources.GalleryServer.Error_Hdr, Message = ex.Message, Style = MessageStyle.Error }; } }