Ejemplo n.º 1
0
        public async Task <IActionResult> EndParty()
        {
            PartyGoer host = await _partyGoerService.GetCurrentPartyGoerAsync();

            if (await _partyService.IsUserHostingAPartyAsync(host))
            {
                if (await _partyService.EndPartyAsync(host))
                {
                    await _logService.LogUserActivityAsync(host, $"User successfully ended party");

                    return(Ok());
                }
                else
                {
                    await _logService.LogUserActivityAsync(host, $"User failed to end party");

                    return(BadRequest("There was an issue with deleting your party"));
                }
            }
            else
            {
                await _logService.LogUserActivityAsync(host, $"User failed to end party because they weren't the host");

                return(BadRequest("Unable to delete party. You are not hosting any parties"));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> EndParty()
        {
            PartyGoer host = new PartyGoer(User.FindFirstValue(ClaimTypes.NameIdentifier));

            if (await _partyService.IsUserHostingAPartyAsync(host))
            {
                if (await _partyService.EndPartyAsync(host))
                {
                    await _logService.LogUserActivityAsync(host.Id, $"User successfully ended party");

                    return(Ok());
                }
                else
                {
                    await _logService.LogUserActivityAsync(host.Id, $"User failed to end party");

                    return(BadRequest("There was an issue with deleting your party"));
                }
            }
            else
            {
                await _logService.LogUserActivityAsync(host.Id, $"User failed to end party because they weren't the host");

                return(BadRequest("Unable to delete party. You are not hosting any parties"));
            }
        }
Ejemplo n.º 3
0
        public async Task HandleAsync(PlaylistEnded args)
        {
            await _logService.LogAppActivityAsync($"Playlist has ended for party with code {args.PartyCode}. Sending to all listeners");

            Party party = await _partyService.GetPartyWithCodeAsync(args.PartyCode);

            if (party.Listeners.Count < 1)
            {
                await party.DeletePlaylistAsync();
                await _partyService.EndPartyAsync(args.PartyCode);
                return;
            }

            List<Track> playlistSongs = await GenerateNewPlaylist(party);
            // If there is atleast 1 person still in the party, regenerate the playlist
            party.Playlist = new Playlist(playlistSongs, party.Listeners, party.PartyCode, party.Playlist.History);

            await party.Playlist.StartAsync();

            await _partyHubContext.Clients.Group(args.PartyCode).SendAsync("UpdatePartyView",
            new
            {
                Song = party.Playlist.CurrentSong,
                Position = party.Playlist.CurrentPositionInSong()
            },
            party.Playlist.History,
            party.Playlist.Queue
            );
        }
Ejemplo n.º 4
0
        public async Task HandleAsync(QueueEnded args)
        {
            await _logService.LogAppActivityAsync($"Playlist has ended for party with code {args.PartyCode}. Sending to all listeners");

            Party party = await _partyService.GetPartyWithCodeAsync(args.PartyCode);

            if (party.GetListeners().Count < 1)
            {
                await _partyService.EndPartyAsync(args.PartyCode);

                return;
            }

            List <Track> playlistSongs = await _partyService.GenerateNewPlaylist(party, args.SeedTracksUris, args.SeedArtistUris);

            await party.AddNewQueueAsync(playlistSongs);

            await _partyHubContext.Clients.Group(args.PartyCode).SendAsync("UpdatePartyView",
                                                                           new
            {
                Song     = party.GetCurrentSong(),
                Position = party.GetCurrentPositionInSong()
            },
                                                                           party.GetHistory(),
                                                                           party.GetQueue()
                                                                           );
        }
Ejemplo n.º 5
0
        public async Task HandleAsync(PlaylistEnded args)
        {
            await _logService.LogAppActivityAsync($"Playlist has ended for party with code {args.PartyCode}. Sending to all listeners");

            Party party = await _partyService.GetPartyWithCodeAsync(args.PartyCode);

            if (party.Listeners.Count < 1)
            {
                await party.DeletePlaylistAsync();

                await _partyService.EndPartyAsync(args.PartyCode);

                return;
            }

            List <Song> songs = new List <Song>();

            foreach (PartyGoer listener in party.Listeners)
            {
                songs.AddRange(await _partyGoerService.GetRecommendedSongsAsync(listener.Id, 5));
            }

            List <Song> playlistSongs = await _spotifyHttpClient.GetRecommendedSongsAsync(party.Listeners.ElementAt(0).Id, songs.GetRandomNItems(5).Select(p => p.TrackUri).ToList(), 0);

            // If there is atleast 1 person still in the party, regenerate the playlist
            party.Playlist = new Playlist(playlistSongs, party.Listeners, party.PartyCode, party.Playlist.History);

            await party.Playlist.StartAsync();

            await _partyHubContext.Clients.Group(args.PartyCode).SendAsync("UpdatePartyView",
                                                                           new
            {
                Song     = party.Playlist.CurrentSong,
                Position = party.Playlist.CurrentPositionInSong()
            },
                                                                           party.Playlist.History,
                                                                           party.Playlist.Queue
                                                                           );
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Logout()
        {
            try
            {
                PartyGoer user = new PartyGoer(User.FindFirstValue(ClaimTypes.NameIdentifier));

                // If the user is joined in a party, REMOVE HIM
                if (await _partyService.IsUserPartyingAsync(user))
                {
                    Task logUserLeavingParty = _logService.LogUserActivityAsync(user, "Leaving party while logging out");
                    await _partyService.LeavePartyAsync(user);

                    await logUserLeavingParty;
                }

                // If the user is hosting a party, END IT
                if (await _partyService.IsUserHostingAPartyAsync(user))
                {
                    Task logUserEndingParty = _logService.LogUserActivityAsync(user, "Ending party while logging out");
                    await _partyService.EndPartyAsync(user);

                    await logUserEndingParty;
                }

                await _authenticationService.LogOutUserAsync(User.FindFirstValue(ClaimTypes.NameIdentifier));

                await HttpContext.SignOutAsync();

                await _logService.LogUserActivityAsync(user, "Successfully logged out");
            }
            catch (Exception ex)
            {
                await _logService.LogExceptionAsync(ex, "Error occurred in Logout()");
            }

            return(RedirectToAction("Index", "Home"));
        }