public async Task Update_ArtistLinks() { // Arrange var circle = _repository.Save(CreateEntry.Circle()); var illustrator = _repository.Save(CreateEntry.Artist(ArtistType.Illustrator)); var contract = new ArtistForEditContract(_vocalist, ContentLanguagePreference.English, new InMemoryImagePersister()) { Groups = new[] { new ArtistForArtistContract { Parent = new ArtistContract(circle, ContentLanguagePreference.English) }, }, Illustrator = new ArtistContract(illustrator, ContentLanguagePreference.English) }; // Act await CallUpdate(contract); // Assert var artistFromRepo = _repository.Load(contract.Id); artistFromRepo.AllGroups.Count.Should().Be(2, "Number of groups"); artistFromRepo.HasGroup(circle).Should().BeTrue("Has group"); artistFromRepo.HasGroup(illustrator).Should().BeTrue("Has illustrator"); artistFromRepo.Groups.First(g => g.Parent.Equals(circle)).LinkType.Should().Be(ArtistLinkType.Group, "Artist link type for circle"); artistFromRepo.Groups.First(g => g.Parent.Equals(illustrator)).LinkType.Should().Be(ArtistLinkType.Illustrator, "Artist link type for illustrator"); }
public void Update_ArtistLinks_ChangeRole() { // Arrange var illustrator = repository.Save(CreateEntry.Artist(ArtistType.Illustrator)); vocalist.AddGroup(illustrator, ArtistLinkType.Illustrator); // Change linked artist from illustrator to voice provider var contract = new ArtistForEditContract(vocalist, ContentLanguagePreference.English) { Illustrator = null, VoiceProvider = new ArtistContract(illustrator, ContentLanguagePreference.English) }; // Act CallUpdate(contract); // Assert vocalist = repository.Load(contract.Id); Assert.AreEqual(1, vocalist.AllGroups.Count, "Number of linked artists"); var link = vocalist.AllGroups[0]; Assert.AreEqual(illustrator, link.Parent, "Linked artist as expected"); Assert.AreEqual(ArtistLinkType.VoiceProvider, link.LinkType, "Link type was updated"); }
public void Update_ArtistLinks() { // Arrange var circle = repository.Save(CreateEntry.Circle()); var illustrator = repository.Save(CreateEntry.Artist(ArtistType.Illustrator)); var contract = new ArtistForEditContract(vocalist, ContentLanguagePreference.English) { Groups = new[] { new ArtistForArtistContract { Parent = new ArtistContract(circle, ContentLanguagePreference.English) }, }, Illustrator = new ArtistContract(illustrator, ContentLanguagePreference.English) }; // Act CallUpdate(contract); // Assert var artistFromRepo = repository.Load(contract.Id); Assert.AreEqual(2, artistFromRepo.AllGroups.Count, "Number of groups"); Assert.IsTrue(artistFromRepo.HasGroup(circle), "Has group"); Assert.IsTrue(artistFromRepo.HasGroup(illustrator), "Has illustrator"); Assert.AreEqual(ArtistLinkType.Group, artistFromRepo.Groups.First(g => g.Parent.Equals(circle)).LinkType, "Artist link type for circle"); Assert.AreEqual(ArtistLinkType.Illustrator, artistFromRepo.Groups.First(g => g.Parent.Equals(illustrator)).LinkType, "Artist link type for illustrator"); }
public void Revert() { // Arrange artist.Description.English = "Original"; var oldVer = repository.HandleTransaction(ctx => queries.Archive(ctx, artist, ArtistArchiveReason.PropertiesUpdated)); var contract = new ArtistForEditContract(artist, ContentLanguagePreference.English); contract.Description.English = "Updated"; CallUpdate(contract); var entryFromRepo = repository.Load <Artist>(artist.Id); Assert.AreEqual("Updated", entryFromRepo.Description.English, "Description was updated"); // Act var result = queries.RevertToVersion(oldVer.Id); // Assert Assert.AreEqual(0, result.Warnings.Length, "Number of warnings"); entryFromRepo = repository.Load <Artist>(result.Id); Assert.AreEqual("Original", entryFromRepo.Description.English, "Description was restored"); var lastVersion = entryFromRepo.ArchivedVersionsManager.GetLatestVersion(); Assert.IsNotNull(lastVersion, "Last version is available"); Assert.AreEqual(ArtistArchiveReason.Reverted, lastVersion.Reason, "Last version archive reason"); Assert.IsFalse(lastVersion.Diff.Picture, "Picture was not changed"); }
public void Update_Names() { // Arrange var contract = new ArtistForEditContract(artist, ContentLanguagePreference.English); contract.Names.First().Value = "Replaced name"; contract.UpdateNotes = "Updated artist"; // Act contract = CallUpdate(contract); // Assert Assert.AreEqual(artist.Id, contract.Id, "Update album Id as expected"); var artistFromRepo = repository.Load(contract.Id); Assert.AreEqual("Replaced name", artistFromRepo.DefaultName); Assert.AreEqual(1, artistFromRepo.Version, "Version"); var archivedVersion = repository.List <ArchivedArtistVersion>().FirstOrDefault(); Assert.IsNotNull(archivedVersion, "Archived version was created"); Assert.AreEqual(artist, archivedVersion.Artist, "Archived version album"); Assert.AreEqual(ArtistArchiveReason.PropertiesUpdated, archivedVersion.Reason, "Archived version reason"); Assert.AreEqual(ArtistEditableFields.Names, archivedVersion.Diff.ChangedFields, "Changed fields"); var activityEntry = repository.List <ActivityEntry>().FirstOrDefault(); Assert.IsNotNull(activityEntry, "Activity entry was created"); Assert.AreEqual(artist, activityEntry.EntryBase, "Activity entry's entry"); Assert.AreEqual(EntryEditEvent.Updated, activityEntry.EditEvent, "Activity entry event type"); }
public async Task Update_ArtistLinks_ChangeRole() { // Arrange var illustrator = _repository.Save(CreateEntry.Artist(ArtistType.Illustrator)); _vocalist.AddGroup(illustrator, ArtistLinkType.Illustrator); // Change linked artist from illustrator to voice provider var contract = new ArtistForEditContract(_vocalist, ContentLanguagePreference.English, new InMemoryImagePersister()) { Illustrator = null, VoiceProvider = new ArtistContract(illustrator, ContentLanguagePreference.English) }; // Act await CallUpdate(contract); // Assert _vocalist = _repository.Load(contract.Id); _vocalist.AllGroups.Count.Should().Be(1, "Number of linked artists"); var link = _vocalist.AllGroups[0]; link.Parent.Should().Be(illustrator, "Linked artist as expected"); link.LinkType.Should().Be(ArtistLinkType.VoiceProvider, "Link type was updated"); }
public async Task Update_Names() { // Arrange var contract = new ArtistForEditContract(_artist, ContentLanguagePreference.English, new InMemoryImagePersister()); contract.Names.First().Value = "Replaced name"; contract.UpdateNotes = "Updated artist"; // Act contract = await CallUpdate(contract); // Assert contract.Id.Should().Be(_artist.Id, "Update album Id as expected"); var artistFromRepo = _repository.Load(contract.Id); artistFromRepo.DefaultName.Should().Be("Replaced name"); artistFromRepo.Version.Should().Be(1, "Version"); var archivedVersion = _repository.List <ArchivedArtistVersion>().FirstOrDefault(); archivedVersion.Should().NotBeNull("Archived version was created"); archivedVersion.Artist.Should().Be(_artist, "Archived version album"); archivedVersion.Reason.Should().Be(ArtistArchiveReason.PropertiesUpdated, "Archived version reason"); archivedVersion.Diff.ChangedFields.Value.Should().Be(ArtistEditableFields.Names, "Changed fields"); var activityEntry = _repository.List <ActivityEntry>().FirstOrDefault(); activityEntry.Should().NotBeNull("Activity entry was created"); activityEntry.EntryBase.Should().Be(_artist, "Activity entry's entry"); activityEntry.EditEvent.Should().Be(EntryEditEvent.Updated, "Activity entry event type"); }
public async Task Revert() { // Arrange _artist.Description.English = "Original"; var oldVer = await _repository.HandleTransactionAsync(ctx => _queries.ArchiveAsync(ctx, _artist, ArtistArchiveReason.PropertiesUpdated)); var contract = new ArtistForEditContract(_artist, ContentLanguagePreference.English, new InMemoryImagePersister()); contract.Description.English = "Updated"; await CallUpdate(contract); var entryFromRepo = _repository.Load <Artist>(_artist.Id); entryFromRepo.Description.English.Should().Be("Updated", "Description was updated"); // Act var result = await _queries.RevertToVersion(oldVer.Id); // Assert result.Warnings.Length.Should().Be(0, "Number of warnings"); entryFromRepo = _repository.Load <Artist>(result.Id); entryFromRepo.Description.English.Should().Be("Original", "Description was restored"); var lastVersion = entryFromRepo.ArchivedVersionsManager.GetLatestVersion(); lastVersion.Should().NotBeNull("Last version is available"); lastVersion.Reason.Should().Be(ArtistArchiveReason.Reverted, "Last version archive reason"); lastVersion.Diff.Picture.IsChanged.Should().BeFalse("Picture was not changed"); }
private async Task <ArtistForEditContract> CallUpdate(Stream image, string mime = MediaTypeNames.Image.Jpeg) { var contract = new ArtistForEditContract(artist, ContentLanguagePreference.English, new InMemoryImagePersister()); using (var stream = image) { contract.Id = await queries.Update(contract, new EntryPictureFileContract(stream, mime, (int)stream.Length, ImagePurpose.Main), permissionContext); } return(contract); }
public void CopyNonEditableFields(ArtistForEditContract artist) { ParamIs.NotNull(() => artist); AllowedEntryStatuses = EntryPermissionManager.AllowedEntryStatuses(MvcApplication.LoginManager); Deleted = artist.Deleted; Draft = artist.Status == EntryStatus.Draft; ValidationResult = artist.ValidationResult; }
public ArtistEditViewModel(ArtistContract artist, IUserPermissionContext permissionContext, ArtistForEditContract editedArtist = null) : this() { ParamIs.NotNull(() => artist); Artist = artist; AllowedEntryStatuses = EntryPermissionManager.AllowedEntryStatuses(permissionContext); EditedArtist = editedArtist; }
private ArtistForEditContract CallUpdate(Stream image, string mime = MediaTypeNames.Image.Jpeg) { var contract = new ArtistForEditContract(artist, ContentLanguagePreference.English); using (var stream = image) { contract.Id = queries.Update(contract, new EntryPictureFileContract { UploadedFile = stream, ContentLength = (int)stream.Length, Mime = mime }, permissionContext); } return(contract); }
public void Ctor_IllustratorIsAlsoManager() { var illustrator = CreateEntry.Artist(ArtistType.Illustrator, id: 1); var artist = CreateEntry.Vocalist(id: 2); artist.AddGroup(illustrator, ArtistLinkType.Illustrator); artist.AddGroup(illustrator, ArtistLinkType.Manager); var result = new ArtistForEditContract(artist, ContentLanguagePreference.Default); Assert.AreEqual(illustrator.Id, result.Illustrator?.Id, "Illustrator"); Assert.AreEqual(1, result.AssociatedArtists.Length, "Illustrator is included in the associated artists list"); var managerRole = result.AssociatedArtists.FirstOrDefault(); Assert.IsNotNull(managerRole, "Manager"); Assert.AreEqual(illustrator.Id, managerRole.Parent.Id, "Manager is the same as illustrator"); Assert.AreEqual(ArtistLinkType.Manager, managerRole.LinkType, "LinkType"); }
public void Ctor_IllustratorIsAlsoManager() { var illustrator = CreateEntry.Artist(ArtistType.Illustrator, id: 1); var artist = CreateEntry.Vocalist(id: 2); artist.AddGroup(illustrator, ArtistLinkType.Illustrator); artist.AddGroup(illustrator, ArtistLinkType.Manager); var result = new ArtistForEditContract(artist, ContentLanguagePreference.Default, new InMemoryImagePersister()); result.Illustrator?.Id.Should().Be(illustrator.Id, "Illustrator"); result.AssociatedArtists.Length.Should().Be(1, "Illustrator is included in the associated artists list"); var managerRole = result.AssociatedArtists.FirstOrDefault(); managerRole.Should().NotBeNull("Manager"); managerRole.Parent.Id.Should().Be(illustrator.Id, "Manager is the same as illustrator"); managerRole.LinkType.Should().Be(ArtistLinkType.Manager, "LinkType"); }
public ArtistEdit(ArtistForEditContract artist) : this() { ParamIs.NotNull(() => artist); ArtistType = artist.ArtistType; DefaultLanguageSelection = artist.TranslatedName.DefaultLanguage; Description = artist.Description; Groups = artist.Groups; Id = artist.Id; Name = artist.Name; NameEnglish = artist.TranslatedName.English; NameJapanese = artist.TranslatedName.Japanese; NameRomaji = artist.TranslatedName.Romaji; Names = artist.Names; Pictures = artist.Pictures; Status = artist.Status; TooManyAlbums = artist.TooManyAlbums; WebLinks = artist.WebLinks.Select(w => new WebLinkDisplay(w)).ToArray(); CopyNonEditableFields(artist); }
public void Update_ArtistLinks_IgnoreInvalid() { // Arrange var circle = repository.Save(CreateEntry.Circle()); var circle2 = repository.Save(CreateEntry.Circle()); // Cannot add character designer for producer var contract = new ArtistForEditContract(artist, ContentLanguagePreference.English) { AssociatedArtists = new[] { new ArtistForArtistContract(new ArtistForArtist(circle, artist, ArtistLinkType.CharacterDesigner), ContentLanguagePreference.English), }, Groups = new[] { new ArtistForArtistContract(new ArtistForArtist(circle2, artist, ArtistLinkType.Group), ContentLanguagePreference.English) } }; // Act CallUpdate(contract); // Assert Assert.AreEqual(1, artist.AllGroups.Count, "Number of linked artists"); Assert.IsFalse(artist.HasGroup(circle), "Character designer was not added"); }
public async Task Update_OriginalName_UpdateArtistStrings() { _artist.Names.Names.Clear(); _artist.Names.Add(new ArtistName(_artist, new LocalizedString("初音ミク", ContentLanguageSelection.Japanese))); _artist.Names.Add(new ArtistName(_artist, new LocalizedString("Hatsune Miku", ContentLanguageSelection.Romaji))); _artist.TranslatedName.DefaultLanguage = ContentLanguageSelection.Japanese; _artist.Names.UpdateSortNames(); _repository.SaveNames(_artist); var song = _repository.Save(CreateEntry.Song()); _repository.Save(song.AddArtist(_artist)); song.UpdateArtistString(); song.ArtistString[ContentLanguagePreference.Default].Should().Be("初音ミク", "Precondition: default name"); var contract = new ArtistForEditContract(_artist, ContentLanguagePreference.English, new InMemoryImagePersister()); contract.DefaultNameLanguage = ContentLanguageSelection.English; await CallUpdate(contract); song.ArtistString[ContentLanguagePreference.Default].Should().Be("Hatsune Miku", "Default name was updated"); }
public void Update_OriginalName_UpdateArtistStrings() { artist.Names.Names.Clear(); artist.Names.Add(new ArtistName(artist, new LocalizedString("初音ミク", ContentLanguageSelection.Japanese))); artist.Names.Add(new ArtistName(artist, new LocalizedString("Hatsune Miku", ContentLanguageSelection.Romaji))); artist.TranslatedName.DefaultLanguage = ContentLanguageSelection.Japanese; artist.Names.UpdateSortNames(); repository.SaveNames(artist); var song = repository.Save(CreateEntry.Song()); repository.Save(song.AddArtist(artist)); song.UpdateArtistString(); Assert.AreEqual("初音ミク", song.ArtistString[ContentLanguagePreference.Default], "Precondition: default name"); var contract = new ArtistForEditContract(artist, ContentLanguagePreference.English, new InMemoryImagePersister()); contract.DefaultNameLanguage = ContentLanguageSelection.English; CallUpdate(contract); Assert.AreEqual("Hatsune Miku", song.ArtistString[ContentLanguagePreference.Default], "Default name was updated"); }
public async Task Update_ArtistLinks_IgnoreInvalid() { // Arrange var circle = _repository.Save(CreateEntry.Circle()); var circle2 = _repository.Save(CreateEntry.Circle()); // Cannot add character designer for producer var contract = new ArtistForEditContract(_artist, ContentLanguagePreference.English, new InMemoryImagePersister()) { AssociatedArtists = new[] { new ArtistForArtistContract(new ArtistForArtist(circle, _artist, ArtistLinkType.CharacterDesigner), ContentLanguagePreference.English), }, Groups = new[] { new ArtistForArtistContract(new ArtistForArtist(circle2, _artist, ArtistLinkType.Group), ContentLanguagePreference.English) } }; // Act await CallUpdate(contract); // Assert _artist.AllGroups.Count.Should().Be(1, "Number of linked artists"); _artist.HasGroup(circle).Should().BeFalse("Character designer was not added"); }
private ArtistEditViewModel CreateArtistEditViewModel(int id, ArtistForEditContract editedArtist) { return(queries.Get(id, album => new ArtistEditViewModel(new ArtistContract(album, PermissionContext.LanguagePreference), PermissionContext, EntryPermissionManager.CanDelete(PermissionContext, album), editedArtist))); }
public async Task <int> Update(ArtistForEditContract properties, EntryPictureFileContract pictureData, IUserPermissionContext permissionContext) { ParamIs.NotNull(() => properties); ParamIs.NotNull(() => permissionContext); return(await repository.HandleTransactionAsync(async ctx => { var artist = await ctx.LoadAsync(properties.Id); VerifyEntryEdit(artist); var diff = new ArtistDiff(DoSnapshot(artist.GetLatestVersion(), await ctx.OfType <User>().GetLoggedUserAsync(permissionContext))); ctx.AuditLogger.SysLog(string.Format("updating properties for {0}", artist)); if (artist.ArtistType != properties.ArtistType) { artist.ArtistType = properties.ArtistType; diff.ArtistType.Set(); } diff.Description.Set(artist.Description.CopyFrom(properties.Description)); if (artist.TranslatedName.DefaultLanguage != properties.DefaultNameLanguage) { artist.TranslatedName.DefaultLanguage = properties.DefaultNameLanguage; diff.OriginalName.Set(); } // Required because of a bug in NHibernate NHibernateUtil.Initialize(artist.Picture); if (pictureData != null) { var parsed = ImageHelper.GetOriginal(pictureData.UploadedFile, pictureData.ContentLength, pictureData.Mime); artist.Picture = new PictureData(parsed); artist.PictureMime = parsed.Mime; pictureData.Id = artist.Id; pictureData.EntryType = EntryType.Artist; var thumbGenerator = new ImageThumbGenerator(imagePersister); thumbGenerator.GenerateThumbsAndMoveImage(pictureData.UploadedFile, pictureData, ImageSizes.Thumb | ImageSizes.SmallThumb | ImageSizes.TinyThumb); diff.Picture.Set(); } if (artist.Status != properties.Status) { artist.Status = properties.Status; diff.Status.Set(); } var nameDiff = artist.Names.Sync(properties.Names, artist); await ctx.OfType <ArtistName>().SyncAsync(nameDiff); if (nameDiff.Changed) { diff.Names.Set(); } if (!artist.BaseVoicebank.NullSafeIdEquals(properties.BaseVoicebank)) { var newBase = await ctx.NullSafeLoadAsync(properties.BaseVoicebank); if (artist.IsValidBaseVoicebank(newBase)) { diff.BaseVoicebank.Set(); artist.SetBaseVoicebank(await ctx.NullSafeLoadAsync(properties.BaseVoicebank)); } } if (!artist.ReleaseDate.Equals(properties.ReleaseDate)) { artist.ReleaseDate = properties.ReleaseDate; diff.ReleaseDate.Set(); } var webLinkDiff = WebLink.Sync(artist.WebLinks, properties.WebLinks, artist); await ctx.OfType <ArtistWebLink>().SyncAsync(webLinkDiff); if (webLinkDiff.Changed) { diff.WebLinks.Set(); } if (diff.ArtistType.IsChanged || diff.Names.IsChanged || diff.OriginalName.IsChanged) { foreach (var song in artist.Songs) { song.Song.UpdateArtistString(); await ctx.UpdateAsync(song); } } var newGroups = properties.Groups .Select(g => new ArtistForArtistContract { Parent = g.Parent, LinkType = ArtistLinkType.Group }) .Concat(new[] { new ArtistForArtistContract { Parent = properties.Illustrator, LinkType = ArtistLinkType.Illustrator }, new ArtistForArtistContract { Parent = properties.VoiceProvider, LinkType = ArtistLinkType.VoiceProvider } }) .Concat(properties.AssociatedArtists) .Where(a => a.Parent != null && ArtistHelper.CanHaveRelatedArtists(artist.ArtistType, a.LinkType, LinkDirection.ManyToOne)) .ToArray(); var groupsDiff = CollectionHelper.Diff(artist.Groups, newGroups, (i, i2) => (i.Parent.Id == i2.Parent.Id && i.LinkType == i2.LinkType)); foreach (var grp in groupsDiff.Removed) { grp.Delete(); await ctx.DeleteAsync(grp); } foreach (var grp in groupsDiff.Added) { var link = artist.AddGroup(ctx.Load(grp.Parent.Id), grp.LinkType); await ctx.SaveAsync(link); } if (groupsDiff.Changed) { diff.Groups.Set(); } var picsDiff = artist.Pictures.SyncPictures(properties.Pictures, ctx.OfType <User>().GetLoggedUser(permissionContext), artist.CreatePicture); ctx.OfType <ArtistPictureFile>().Sync(picsDiff); var entryPictureFileThumbGenerator = new ImageThumbGenerator(pictureFilePersister); artist.Pictures.GenerateThumbsAndMoveImage(entryPictureFileThumbGenerator, picsDiff.Added, ImageSizes.Original | ImageSizes.Thumb); if (picsDiff.Changed) { diff.Pictures.Set(); } var logStr = string.Format("updated properties for artist {0} ({1})", entryLinkFactory.CreateEntryLink(artist), diff.ChangedFieldsString) + (properties.UpdateNotes != string.Empty ? " " + properties.UpdateNotes : string.Empty) .Truncate(400); var archived = await ArchiveAsync(ctx, artist, diff, ArtistArchiveReason.PropertiesUpdated, properties.UpdateNotes); await ctx.UpdateAsync(artist); await ctx.AuditLogger.AuditLogAsync(logStr); await AddEntryEditedEntryAsync(ctx.OfType <ActivityEntry>(), artist, EntryEditEvent.Updated, archived); return artist.Id; })); }
public void UpdateBasicProperties(ArtistForEditContract properties, PictureDataContract pictureData, IUserPermissionContext permissionContext) { ParamIs.NotNull(() => properties); ParamIs.NotNull(() => permissionContext); HandleTransaction(session => { var artist = session.Load <Artist>(properties.Id); VerifyEntryEdit(artist); var diff = new ArtistDiff(DoSnapshot(artist.GetLatestVersion(), GetLoggedUser(session))); SysLog(string.Format("updating properties for {0}", artist)); if (artist.ArtistType != properties.ArtistType) { artist.ArtistType = properties.ArtistType; diff.ArtistType = true; } if (artist.Description != properties.Description) { artist.Description = properties.Description; diff.Description = true; } if (artist.TranslatedName.DefaultLanguage != properties.TranslatedName.DefaultLanguage) { artist.TranslatedName.DefaultLanguage = properties.TranslatedName.DefaultLanguage; diff.OriginalName = true; } NHibernateUtil.Initialize(artist.Picture); if (pictureData != null) { artist.Picture = new PictureData(pictureData); diff.Picture = true; } if (artist.Status != properties.Status) { artist.Status = properties.Status; diff.Status = true; } var nameDiff = artist.Names.Sync(properties.Names.AllNames, artist); SessionHelper.Sync(session, nameDiff); if (nameDiff.Changed) { diff.Names = true; } var validWebLinks = properties.WebLinks.Where(w => !string.IsNullOrEmpty(w.Url)); var webLinkDiff = WebLink.Sync(artist.WebLinks, validWebLinks, artist); SessionHelper.Sync(session, webLinkDiff); if (webLinkDiff.Changed) { diff.WebLinks = true; } if (diff.ArtistType || diff.Names) { foreach (var song in artist.Songs) { song.Song.UpdateArtistString(); session.Update(song); } } var groupsDiff = CollectionHelper.Diff(artist.Groups, properties.Groups, (i, i2) => (i.Id == i2.Id)); foreach (var grp in groupsDiff.Removed) { grp.Delete(); session.Delete(grp); } foreach (var grp in groupsDiff.Added) { var link = artist.AddGroup(session.Load <Artist>(grp.Group.Id)); session.Save(link); } if (groupsDiff.Changed) { diff.Groups = true; } var picsDiff = artist.Pictures.SyncPictures(properties.Pictures, GetLoggedUser(session), artist.CreatePicture); SessionHelper.Sync(session, picsDiff); ImageHelper.GenerateThumbsAndMoveImages(picsDiff.Added); if (picsDiff.Changed) { diff.Pictures = true; } /* * var albumGetter = new Func<AlbumForArtistEditContract, Album>(contract => { * * Album album; * * if (contract.AlbumId != 0) { * * album = session.Load<Album>(contract.AlbumId); * * } else { * * AuditLog(string.Format("creating a new album '{0}' to {1}", contract.AlbumName, artist)); * * album = new Album(contract.AlbumName); * session.Save(album); * * Services.Albums.Archive(session, album, AlbumArchiveReason.Created, * string.Format("Created for artist '{0}'", artist.DefaultName)); * * AuditLog(string.Format("created {0} for {1}", * EntryLinkFactory.CreateEntryLink(album), EntryLinkFactory.CreateEntryLink(artist)), session); * AddEntryEditedEntry(session, album, EntryEditEvent.Created); * * } * * return album; * * }); * * if (properties.AlbumLinks != null * && !properties.TooManyAlbums * && (properties.AlbumLinks.Any() || artist.Albums.Count() < ArtistForEditContract.MaxAlbums / 2) * && artist.Albums.Count() <= ArtistForEditContract.MaxAlbums) { * * var albumDiff = artist.SyncAlbums(properties.AlbumLinks, albumGetter); * * SessionHelper.Sync(session, albumDiff); * * if (albumDiff.Changed) { * * diff.Albums = true; * * var add = string.Join(", ", albumDiff.Added.Select(i => i.Album.ToString())); * var rem = string.Join(", ", albumDiff.Removed.Select(i => i.Album.ToString())); * * var str = string.Format("edited albums (added: {0}, removed: {1})", add, rem) * .Truncate(300); * * AuditLog(str, session); * * } * * }*/ var logStr = string.Format("updated properties for {0} ({1})", EntryLinkFactory.CreateEntryLink(artist), diff.ChangedFieldsString) + (properties.UpdateNotes != string.Empty ? " " + properties.UpdateNotes : string.Empty) .Truncate(400); AuditLog(logStr, session); AddEntryEditedEntry(session, artist, EntryEditEvent.Updated); Archive(session, artist, diff, ArtistArchiveReason.PropertiesUpdated, properties.UpdateNotes); session.Update(artist); return(true); }); }
public int Update(ArtistForEditContract properties, EntryPictureFileContract pictureData, IUserPermissionContext permissionContext) { ParamIs.NotNull(() => properties); ParamIs.NotNull(() => permissionContext); return(repository.HandleTransaction(ctx => { var artist = ctx.Load(properties.Id); VerifyEntryEdit(artist); var diff = new ArtistDiff(DoSnapshot(artist.GetLatestVersion(), ctx.OfType <User>().GetLoggedUser(permissionContext))); ctx.AuditLogger.SysLog(string.Format("updating properties for {0}", artist)); if (artist.ArtistType != properties.ArtistType) { artist.ArtistType = properties.ArtistType; diff.ArtistType = true; } if (artist.Description != properties.Description) { artist.Description = properties.Description; diff.Description = true; } if (artist.TranslatedName.DefaultLanguage != properties.DefaultNameLanguage) { artist.TranslatedName.DefaultLanguage = properties.DefaultNameLanguage; diff.OriginalName = true; } // Required because of a bug in NHibernate NHibernateUtil.Initialize(artist.Picture); if (pictureData != null) { var parsed = ImageHelper.GetOriginal(pictureData.UploadedFile, pictureData.ContentLength, pictureData.Mime); artist.Picture = new PictureData(parsed); artist.PictureMime = parsed.Mime; pictureData.Id = artist.Id; pictureData.EntryType = EntryType.Artist; var thumbGenerator = new ImageThumbGenerator(imagePersister); thumbGenerator.GenerateThumbsAndMoveImage(pictureData.UploadedFile, pictureData, ImageSizes.Thumb | ImageSizes.SmallThumb | ImageSizes.TinyThumb); diff.Picture = true; } if (artist.Status != properties.Status) { artist.Status = properties.Status; diff.Status = true; } var nameDiff = artist.Names.Sync(properties.Names, artist); ctx.OfType <ArtistName>().Sync(nameDiff); if (nameDiff.Changed) { diff.Names = true; } if (!artist.BaseVoicebank.NullSafeIdEquals(properties.BaseVoicebank)) { var newBase = ctx.NullSafeLoad(properties.BaseVoicebank); if (artist.IsValidBaseVoicebank(newBase)) { diff.BaseVoicebank = true; artist.SetBaseVoicebank(ctx.NullSafeLoad(properties.BaseVoicebank)); } } var validWebLinks = properties.WebLinks.Where(w => !string.IsNullOrEmpty(w.Url)); var webLinkDiff = WebLink.Sync(artist.WebLinks, validWebLinks, artist); ctx.OfType <ArtistWebLink>().Sync(webLinkDiff); if (webLinkDiff.Changed) { diff.WebLinks = true; } if (diff.ArtistType || diff.Names) { foreach (var song in artist.Songs) { song.Song.UpdateArtistString(); ctx.Update(song); } } var groupsDiff = CollectionHelper.Diff(artist.Groups, properties.Groups, (i, i2) => (i.Id == i2.Id)); foreach (var grp in groupsDiff.Removed) { grp.Delete(); ctx.Delete(grp); } foreach (var grp in groupsDiff.Added) { var link = artist.AddGroup(ctx.Load(grp.Group.Id)); ctx.Save(link); } if (groupsDiff.Changed) { diff.Groups = true; } var picsDiff = artist.Pictures.SyncPictures(properties.Pictures, ctx.OfType <User>().GetLoggedUser(permissionContext), artist.CreatePicture); ctx.OfType <ArtistPictureFile>().Sync(picsDiff); ImageHelper.GenerateThumbsAndMoveImages(picsDiff.Added); if (picsDiff.Changed) { diff.Pictures = true; } var logStr = string.Format("updated properties for artist {0} ({1})", entryLinkFactory.CreateEntryLink(artist), diff.ChangedFieldsString) + (properties.UpdateNotes != string.Empty ? " " + properties.UpdateNotes : string.Empty) .Truncate(400); ctx.AuditLogger.AuditLog(logStr); AddEntryEditedEntry(ctx.OfType <ActivityEntry>(), artist, EntryEditEvent.Updated); Archive(ctx, artist, diff, ArtistArchiveReason.PropertiesUpdated, properties.UpdateNotes); ctx.Update(artist); return artist.Id; })); }
private async Task <ArtistForEditContract> CallUpdate(ArtistForEditContract contract) { contract.Id = await _queries.Update(contract, null, _permissionContext); return(contract); }
private ArtistForEditContract CallUpdate(ArtistForEditContract contract) { contract.Id = queries.Update(contract, null, permissionContext); return(contract); }