Esempio n. 1
0
        public TResult FindTagForEntryType <TResult>(EntryTypeAndSubType entryType, Func <Tag, ContentLanguagePreference, TResult> fac, bool exactOnly = false)
        {
            return(HandleQuery(ctx =>
            {
                var tag = ctx.Query <EntryTypeToTagMapping>()
                          .Where(m => m.EntryType == entryType.EntryType && m.SubType == entryType.SubType)
                          .Select(m => m.Tag)
                          .FirstOrDefault();

                if (tag == null && !exactOnly)
                {
                    tag = ctx.Query <EntryTypeToTagMapping>()
                          .Where(m => m.EntryType == entryType.EntryType && m.SubType == "")
                          .Select(m => m.Tag)
                          .FirstOrDefault();
                }

                if (tag == null && !exactOnly)
                {
                    tag = ctx.Query <EntryTypeToTagMapping>()
                          .Where(m => m.EntryType == EntryType.Undefined)
                          .Select(m => m.Tag)
                          .FirstOrDefault();
                }

                return tag != null ? fac(tag, LanguagePreference) : default;
            }));
        }
Esempio n. 2
0
 public static string EntrySubTypeName(EntryTypeAndSubType fullEntryType)
 {
     return(fullEntryType.EntryType switch
     {
         EntryType.Album => DiscTypeName(EnumVal <DiscType> .Parse(fullEntryType.SubType)),
         EntryType.Artist => ArtistTypeName(EnumVal <ArtistType> .Parse(fullEntryType.SubType)),
         EntryType.ReleaseEvent => ReleaseEventCategoryNames[EnumVal <EventCategory> .Parse(fullEntryType.SubType)],
         EntryType.Song => SongTypeNames[EnumVal <SongType> .Parse(fullEntryType.SubType)],
         _ => string.Empty,
     });
Esempio n. 3
0
        public async Task GetTagSuggestions_IgnoreCoverTagIfTypeIsCover()
        {
            var coverTag = _repository.Save(CreateEntry.Tag("cover"));

            _repository.Save(new TagMapping(coverTag, "cover"));
            _repository.Save(new EntryTypeToTagMapping(EntryTypeAndSubType.Create(EntryType.Song, SongType.Cover), coverTag));

            _pvParser.ResultFunc = (url, meta) => CreateEntry.VideoUrlParseResultWithTitle(tags: new[] { "cover" });
            _song.SongType       = SongType.Cover;
            _song.PVs.Add(new PVForSong(_song, new PVContract {
                Service = PVService.NicoNicoDouga, PVType = PVType.Original, PVId = "sm393939"
            }));

            var result = await _queries.GetTagSuggestionsAsync(_song.Id);

            result.Count.Should().Be(0, "Cover tag suggestion ignored");
        }
Esempio n. 4
0
        public async Task Create_Tags_IgnoreCoverIfSongTypeIsCover()
        {
            var coverTag = _repository.Save(CreateEntry.Tag("cover"));

            _repository.Save(new TagMapping(coverTag, "cover"));
            _repository.Save(new EntryTypeToTagMapping(EntryTypeAndSubType.Create(EntryType.Song, SongType.Cover), coverTag));

            _pvParser.ResultFunc      = (url, meta) => CreateEntry.VideoUrlParseResultWithTitle(tags: new[] { "cover" });
            _newSongContract.SongType = SongType.Cover;

            var id = (await CallCreate()).Id;

            _song = _repository.Load(id);

            _song.SongType.Should().Be(SongType.Cover, "SongType");
            _song.Tags.Tags.Count().Should().Be(0, "No tags added");
        }
Esempio n. 5
0
        public static string EntryIndex(this UrlHelper urlHelper, EntryTypeAndSubType fullEntryType)
        {
            SearchRouteParams searchRouteParams = null;

            switch (fullEntryType.EntryType)
            {
            case EntryType.Artist:
                searchRouteParams = new SearchRouteParams(EntryType.Artist)
                {
                    artistType = EnumVal <ArtistType> .ParseSafe(fullEntryType.SubType)
                };
                break;

            case EntryType.Album:
                searchRouteParams = new SearchRouteParams(EntryType.Album)
                {
                    discType = EnumVal <DiscType> .ParseSafe(fullEntryType.SubType)
                };
                break;

            case EntryType.Song:
                searchRouteParams = new SearchRouteParams(EntryType.Song)
                {
                    songType = EnumVal <SongType> .ParseSafe(fullEntryType.SubType)
                };
                break;

            case EntryType.ReleaseEvent:
                searchRouteParams = new SearchRouteParams(EntryType.ReleaseEvent);
                break;

            case EntryType.Tag:
                searchRouteParams = new SearchRouteParams(EntryType.Tag);
                break;
            }

            if (searchRouteParams != null)
            {
                return(urlHelper.Action("Index", "Search", searchRouteParams));
            }

            return("");
        }
 public EntryTypeToTagMapping(EntryTypeAndSubType entryType, Tag tag)
 {
     EntryType = entryType.EntryType;
     SubType   = entryType.SubType;
     Tag       = tag;
 }
Esempio n. 7
0
 public Tag GetTag(EntryTypeAndSubType fullEntryType) => ctx.NullSafeLoad <Tag>(GetTagId(fullEntryType.EntryType, fullEntryType.SubType));
Esempio n. 8
0
 public static string TagUrlForEntryType(this UrlHelper urlHelper, EntryTypeAndSubType entryType)
 {
     return(urlHelper.Action("DetailsByEntryType", "Tag", new { entryType = entryType.EntryType, subType = entryType.SubType }));
 }
Esempio n. 9
0
 public static string TagUrlForEntryType <TSubType>(this UrlHelper urlHelper, EntryType entryType, TSubType subType)
     where TSubType : struct, Enum
 {
     return(TagUrlForEntryType(urlHelper, EntryTypeAndSubType.Create(entryType, subType)));
 }
Esempio n. 10
0
 public Tag GetTag(EntryTypeAndSubType fullEntryType) => null;