예제 #1
0
        public void AddSongTags(int songId, string[] tags)
        {
            ParamIs.NotNull(() => tags);

            VerifyManageDatabase();

            repository.HandleTransaction(ctx => {
                tags = tags.Distinct(StringComparer.InvariantCultureIgnoreCase).ToArray();

                var user = ctx.GetLoggedUser(PermissionContext);
                var song = ctx.OfType <Song>().Load(songId);

                ctx.AuditLogger.AuditLog(string.Format("appending {0} with {1}",
                                                       entryLinkFactory.CreateEntryLink(song), string.Join(", ", tags)), user);

                var tagFactory   = new TagFactoryRepository(ctx.OfType <Tag>(), new AgentLoginData(user));
                var existingTags = TagHelpers.GetTags(ctx.OfType <Tag>(), tags);

                song.Tags.SyncVotes(user, tags, existingTags, tagFactory, new SongTagUsageFactoryRepository(ctx.OfType <SongTagUsage>(), song), onlyAdd: true);
            });
        }
예제 #2
0
        public TagUsageContract[] SaveTags(int albumId, string[] tags)
        {
            ParamIs.NotNull(() => tags);

            VerifyManageDatabase();

            return(HandleTransaction(session => {
                tags = tags.Distinct(new CaseInsensitiveStringComparer()).ToArray();

                var user = session.Load <User>(PermissionContext.LoggedUser.Id);
                var album = session.Load <Album>(albumId);

                AuditLog(string.Format("tagging {0} with {1}",
                                       EntryLinkFactory.CreateEntryLink(album), string.Join(", ", tags)), session, user);

                var existingTags = TagHelpers.GetTags(session, tags);

                album.Tags.SyncVotes(user, tags, existingTags, new TagFactory(session, new AgentLoginData(user)), new AlbumTagUsageFactory(session, album));

                return album.Tags.Usages.OrderByDescending(u => u.Count).Select(t => new TagUsageContract(t)).ToArray();
            }));
        }
예제 #3
0
        public TagUsageContract[] SaveTags(int songId, string[] tags)
        {
            ParamIs.NotNull(() => tags);

            VerifyManageDatabase();

            return(HandleTransaction(session => {
                tags = tags.Distinct(StringComparer.InvariantCultureIgnoreCase).ToArray();

                var user = session.Load <User>(PermissionContext.LoggedUser.Id);
                var song = session.Load <Song>(songId);

                AuditLog(string.Format("tagging {0} with {1}",
                                       EntryLinkFactory.CreateEntryLink(song), string.Join(", ", tags)), session, user);

                var existingTags = TagHelpers.GetTags(session, tags);

                song.Tags.SyncVotes(user, tags, existingTags, new TagFactory(session, new AgentLoginData(user)), new SongTagUsageFactory(session, song));

                return song.Tags.Usages.OrderByDescending(u => u.Count).Select(t => new TagUsageContract(t)).ToArray();
            }));
        }