예제 #1
0
        public async Task <IActionResult> Jukebox()
        {
            //check if user forcely quit editing the playlist and delete it
            var appUser = await _userManager.GetUserAsync(User);

            var user = await _jukeboxRepository.GetUserAsync(appUser.Id);

            var myPlaylists = await _jukeboxRepository.GetAllFilteredPlaylistsAsync(p => p.User.Id.Equals(user.Id));

            var playlist = myPlaylists.FirstOrDefault(p => !p.IsCreated);

            if (playlist != null)
            {
                var playlistUser = playlist.User;
                playlistUser.Playlists.Remove(playlist);
                //sending playlistUser cause current user can be admin and other users can't even reach this method
                await _jukeboxRepository.RemovePlaylistAsync(playlist.Id, playlistUser.Id);

                await _jukeboxRepository.UpdateUserAsync(playlistUser, playlistUser.Id);
            }
            var allPlaylists = await _jukeboxRepository.GetAllPlaylistsAsync();

            var model = new JukeboxViewModel(allPlaylists);

            return(View(model));
        }
예제 #2
0
        public async Task <IActionResult> Logout()
        {
            //check if user forcely quit editing the playlist and delete it
            var appUser = await _userManager.GetUserAsync(User);

            var user = await _jukeboxRepository.GetUserAsync(appUser.Id);

            var myPlaylists = await _jukeboxRepository.GetAllFilteredPlaylistsAsync(p => p.User.Id.Equals(user.Id));

            var playlist = myPlaylists.FirstOrDefault(p => !p.IsCreated);

            if (playlist != null)
            {
                var playlistUser = playlist.User;
                playlistUser.Playlists.Remove(playlist);
                //sending playlistUser cause current user can be admin and other users can't even reach this method
                await _jukeboxRepository.RemovePlaylistAsync(playlist.Id, playlistUser.Id);

                await _jukeboxRepository.UpdateUserAsync(playlistUser, playlistUser.Id);
            }
            await _signInManager.SignOutAsync();

            _logger.LogInformation("User logged out.");
            return(RedirectToAction("Index", "Jukebox", new { area = "" }));
        }
        public async Task <IActionResult> Index()
        {
            //check if user forcely quit editing the playlist and delete it
            var appUser = await _userManager.GetUserAsync(User);

            var myUser = await _jukeboxRepository.GetUserAsync(appUser.Id);

            var myPlaylists = await _jukeboxRepository.GetAllFilteredPlaylistsAsync(p => p.User.Id.Equals(myUser.Id));

            var playlist = myPlaylists.FirstOrDefault(p => !p.IsCreated);

            if (playlist != null)
            {
                var playlistUser = playlist.User;
                playlistUser.Playlists.Remove(playlist);
                //sending playlistUser cause current user can be admin and other users can't even reach this method
                await _jukeboxRepository.RemovePlaylistAsync(playlist.Id, playlistUser.Id);

                await _jukeboxRepository.UpdateUserAsync(playlistUser, playlistUser.Id);
            }
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            var model = new IndexViewModel
            {
                Username         = user.UserName,
                Email            = user.Email,
                PhoneNumber      = user.PhoneNumber,
                IsEmailConfirmed = user.EmailConfirmed,
                StatusMessage    = StatusMessage
            };

            return(View(model));
        }