public void Archive(IRepositoryContext <SongList> ctx, SongList songList, SongListDiff diff, EntryEditEvent reason) { var agentLoginData = ctx.CreateAgentLoginData(PermissionContext); var archived = songList.CreateArchivedVersion(diff, agentLoginData, reason); ctx.OfType <ArchivedSongListVersion>().Save(archived); }
public ArchivedSongListVersion Archive(IDatabaseContext <SongList> ctx, SongList songList, SongListDiff diff, EntryEditEvent reason, string notes = "") { var agentLoginData = ctx.CreateAgentLoginData(PermissionContext); var archived = songList.CreateArchivedVersion(diff, agentLoginData, reason, notes); ctx.OfType <ArchivedSongListVersion>().Save(archived); return(archived); }
public int UpdateSongList(SongListForEditContract contract, UploadedFileContract uploadedFile) { ParamIs.NotNull(() => contract); PermissionContext.VerifyPermission(PermissionToken.EditProfile); return(repository.HandleTransaction(ctx => { var user = GetLoggedUser(ctx); SongList list; if (contract.Id == 0) { list = CreateSongList(ctx, contract, uploadedFile); } else { list = ctx.Load(contract.Id); var diff = new SongListDiff(); EntryPermissionManager.VerifyEdit(PermissionContext, list); if (list.Description != contract.Description) { diff.Description.Set(); list.Description = contract.Description ?? string.Empty; } if (list.Name != contract.Name) { diff.Name.Set(); list.Name = contract.Name; } if (EntryPermissionManager.CanManageFeaturedLists(PermissionContext) && list.FeaturedCategory != contract.FeaturedCategory) { diff.FeaturedCategory.Set(); list.FeaturedCategory = contract.FeaturedCategory; } if (list.EventDate != contract.EventDate) { diff.SetChanged(SongListEditableFields.EventDate); list.EventDate = contract.EventDate; } if (list.Status != contract.Status) { diff.Status.Set(); list.Status = contract.Status; } var songDiff = list.SyncSongs(contract.SongLinks, c => ctx.OfType <Song>().Load(c.Song.Id)); if (songDiff.Changed) { diff.Songs.Set(); } ctx.OfType <SongInList>().Sync(songDiff); if (uploadedFile != null) { diff.Thumbnail.Set(); SetThumb(list, uploadedFile); } ctx.Update(list); ctx.AuditLogger.AuditLog( string.Format("updated song list {0} ({1})", entryLinkFactory.CreateEntryLink(list), diff.ChangedFieldsString), user); var archived = Archive(ctx, list, diff, EntryEditEvent.Updated, contract.UpdateNotes); if (list.FeaturedList) { AddEntryEditedEntry(ctx.OfType <ActivityEntry>(), list, EntryEditEvent.Updated, archived); } } return list.Id; })); }
public virtual ArchivedSongListVersion CreateArchivedVersion(SongListDiff diff, AgentLoginData author, EntryEditEvent reason) { var archived = new ArchivedSongListVersion(this, diff, author, reason); ArchivedVersionsManager.Add(archived); return archived; }