From 4860d9a1859980d2d1ad4a645b0b8b2df2f4ca50 Mon Sep 17 00:00:00 2001 From: Steven Hildreth Date: Sat, 29 Dec 2018 22:34:32 -0600 Subject: [PATCH] que work --- Roadie.Api.Services/ArtistService.cs | 15 +++++++++++++++ Roadie.Api.Services/ReleaseService.cs | 15 +++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Roadie.Api.Services/ArtistService.cs b/Roadie.Api.Services/ArtistService.cs index 92ebb2c..c34ebfb 100644 --- a/Roadie.Api.Services/ArtistService.cs +++ b/Roadie.Api.Services/ArtistService.cs @@ -412,6 +412,20 @@ namespace Roadie.Api.Services .Distinct() .ToArray(); } + int[] genreArtistIds = new int[0]; + var isFilteredToGenre = false; + if(!string.IsNullOrEmpty(request.Filter) && request.Filter.StartsWith(":genre", StringComparison.OrdinalIgnoreCase)) + { + var genreFilter = request.Filter.Replace(":genre ", ""); + genreArtistIds = (from ag in this.DbContext.ArtistGenres + join g in this.DbContext.Genres on ag.GenreId equals g.Id + where g.Name.Contains(genreFilter) + select ag.ArtistId) + .Distinct() + .ToArray(); + isFilteredToGenre = true; + request.Filter = null; + } var onlyWithReleases = onlyIncludeWithReleases ?? true; var result = (from a in this.DbContext.Artists where (!onlyWithReleases || a.ReleaseCount > 0) @@ -420,6 +434,7 @@ namespace Roadie.Api.Services where (request.FilterValue == "" || (a.Name.Contains(request.FilterValue) || a.SortName.Contains(request.FilterValue) || a.AlternateNames.Contains(request.FilterValue))) where (!request.FilterFavoriteOnly || favoriteArtistIds.Contains(a.Id)) where (request.FilterToLabelId == null || labelArtistIds.Contains(a.Id)) + where (!isFilteredToGenre || genreArtistIds.Contains(a.Id)) select new ArtistList { DatabaseId = a.Id, diff --git a/Roadie.Api.Services/ReleaseService.cs b/Roadie.Api.Services/ReleaseService.cs index 256b0b0..3a14af8 100644 --- a/Roadie.Api.Services/ReleaseService.cs +++ b/Roadie.Api.Services/ReleaseService.cs @@ -181,12 +181,18 @@ namespace Roadie.Api.Services ).ToArray(); } int[] genreReleaseIds = new int[0]; - if (!string.IsNullOrEmpty(request.FilterByGenre)) + var isFilteredToGenre = false; + if (!string.IsNullOrEmpty(request.FilterByGenre) || (!string.IsNullOrEmpty(request.Filter) && request.Filter.StartsWith(":genre", StringComparison.OrdinalIgnoreCase))) { + var genreFilter = request.FilterByGenre ?? (request.Filter ?? string.Empty).Replace(":genre ", "", StringComparison.OrdinalIgnoreCase); genreReleaseIds = (from rg in this.DbContext.ReleaseGenres join g in this.DbContext.Genres on rg.GenreId equals g.Id - where g.Name == request.FilterByGenre - select rg.ReleaseId).ToArray(); + where g.Name.Contains(genreFilter) + select rg.ReleaseId) + .Distinct() + .ToArray(); + request.Filter = null; + isFilteredToGenre = true; } if (request.FilterFromYear.HasValue || request.FilterToYear.HasValue) { @@ -213,7 +219,7 @@ namespace Roadie.Api.Services where (request.FilterToArtistId == null || r.Artist.RoadieId == request.FilterToArtistId) where (request.FilterToCollectionId == null || collectionReleaseIds.Contains(r.Id)) where (!request.FilterFavoriteOnly || favoriteReleaseIds.Contains(r.Id)) - where (request.FilterByGenre == null || genreReleaseIds.Contains(r.Id)) + where (!isFilteredToGenre || genreReleaseIds.Contains(r.Id)) where (request.FilterFromYear == null || r.ReleaseDate != null && r.ReleaseDate.Value.Year <= request.FilterFromYear) where (request.FilterToYear == null || r.ReleaseDate != null && r.ReleaseDate.Value.Year >= request.FilterToYear) where (request.FilterValue == "" || (r.Title.Contains(request.FilterValue) || r.AlternateNames.Contains(request.FilterValue))) @@ -879,6 +885,7 @@ namespace Roadie.Api.Services Text = track.Title, Value = track.RoadieId.ToString() }; + t.MediaNumber = rm.MediaNumber; t.CssClass = string.IsNullOrEmpty(track.Hash) ? "Missing" : "Ok"; t.TrackArtist = track.TrackArtist != null ? ArtistList.FromDataArtist(track.TrackArtist, this.MakeArtistThumbnailImage(track.TrackArtist.RoadieId)) : null; t.TrackPlayUrl = $"{ this.HttpContext.BaseUrl }/play/track/{ t.Id}.mp3";