private async Task <Song> GetSongDto(Song song, SongPick pickReason) { var user = await GetUser(); if (user != null && song.Id != null) { var songLikeId = Like.GetLikeId(user.Id, song.Id); var songLike = await DbSession.LoadOptionalAsync <Like>(songLikeId); var status = songLike != null ? songLike.Status : LikeStatus.None; return(song.ToDto(status, pickReason)); } return(song.ToDto()); }
public async Task <string?> GetPending() { var userId = GetUserId(); if (string.IsNullOrEmpty(userId)) { return(null); } var recent = DateTime.UtcNow.Subtract(songRequestValidTime); var pendingSongReqs = await DbSession .Query <SongRequest>() .OrderByDescending(r => r.DateTime) .Where(r => r.DateTime >= recent) .Take(10) .ToListAsync(); var validSongRequest = pendingSongReqs .OrderBy(d => d.DateTime) // OrderBy to give us the oldest of the pending song requests first. .FirstOrDefault(s => !s.PlayedForUserIds.Contains(userId)); var updatedSongRequest = default(SongRequest); if (validSongRequest != null) { updatedSongRequest = await AddUserToSongRequestPlayedList(validSongRequest, userId); } // We've got a valid song request. Verify the user hasn't disliked this song. if (updatedSongRequest != null) { var songLikeId = Like.GetLikeId(userId, updatedSongRequest.SongId); var songLike = await DbSession.LoadOptionalAsync <Like>(songLikeId); var userDislikesSong = songLike?.Status == LikeStatus.Dislike; if (!userDislikesSong) { return(updatedSongRequest.SongId); } } return(null); }