From b91a72e920f125fc3263e1c1de4e0c580f5b6207 Mon Sep 17 00:00:00 2001 From: Steven Hildreth Date: Tue, 25 Dec 2018 19:28:36 -0600 Subject: [PATCH] release, artist and trackArtist userRating on track list --- RoadieApi/Services/TrackService.cs | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/RoadieApi/Services/TrackService.cs b/RoadieApi/Services/TrackService.cs index 0edbcd7..8075697 100644 --- a/RoadieApi/Services/TrackService.cs +++ b/RoadieApi/Services/TrackService.cs @@ -479,6 +479,52 @@ namespace Roadie.Api.Services }; } } + + var releaseIds = rows.Select(x => x.Release.DatabaseId).Distinct().ToArray(); + var userReleaseRatings = (from ur in this.DbContext.UserReleases + where releaseIds.Contains(ur.ReleaseId) + select ur).ToArray(); + + foreach(var userReleaseRating in userReleaseRatings) + { + foreach(var row in rows.Where(x => x.Release.DatabaseId == userReleaseRating.ReleaseId)) + { + row.Release.UserRating = userReleaseRating.Adapt(); + } + } + + var artistIds = rows.Select(x => x.Artist.DatabaseId).ToArray(); + if (artistIds != null && artistIds.Any()) + { + var userArtistRatings = (from ua in this.DbContext.UserArtists + where ua.UserId == roadieUser.Id + where artistIds.Contains(ua.ArtistId) + select ua).ToArray(); + foreach (var userArtistRating in userArtistRatings) + { + foreach (var artistTrack in rows.Where(x => x.Artist.DatabaseId == userArtistRating.ArtistId)) + { + artistTrack.Artist.UserRating = userArtistRating.Adapt(); + } + } + } + + var trackArtistIds = rows.Where(x => x.TrackArtist != null).Select(x => x.TrackArtist.DatabaseId).ToArray(); + if (trackArtistIds != null && trackArtistIds.Any()) + { + var userTrackArtistRatings = (from ua in this.DbContext.UserArtists + where ua.UserId == roadieUser.Id + where trackArtistIds.Contains(ua.ArtistId) + select ua).ToArray(); + foreach (var userTrackArtistRating in userTrackArtistRatings) + { + foreach (var artistTrack in rows.Where(x => x.TrackArtist.DatabaseId == userTrackArtistRating.ArtistId)) + { + artistTrack.Artist.UserRating = userTrackArtistRating.Adapt(); + } + } + } + } if (rows.Any())