Ejemplo n.º 1
0
        protected Paging <SimplePlaylist> GetPlaylists(Token token, string profileId)
        {
            var playlist = _playlistService.GetPlaylists(token, profileId);

            if (playlist != null && playlist.Items.Count == 0)
            {
                FullPlaylist fullPlaylist = _paradifyService.CreatePlaylist(profileId, "Paradify Playlist", _tokenCookieService.Get());

                if (!string.IsNullOrEmpty(fullPlaylist.Id))
                {
                    playlist = _playlistService.GetPlaylists(_tokenCookieService, profileId);
                }
            }

            return(playlist);
        }
Ejemplo n.º 2
0
        public ActionResult GetPlaylists()
        {
            PrivateProfile profile = _userService.GetMe(_tokenCookieService);

            var playlist = _playlistService.GetPlaylists(_tokenCookieService, profile.Id);

            if (playlist != null && playlist.Items.Count == 0)
            {
                FullPlaylist fullPlaylist = _paradifyService.CreatePlaylist(profile.Id, "Paradify Playlist", _tokenCookieService.Get());

                if (!string.IsNullOrEmpty(fullPlaylist.Id))
                {
                    playlist = _playlistService.GetPlaylists(_tokenCookieService, profile.Id);
                }
            }

            return(PartialView("~/Views/SearchP/PlaylistPartial.cshtml", playlist.Items));
        }
Ejemplo n.º 3
0
        public ActionResult Index(string q, string t)
        {
            _search  = q;
            _trackId = t;

            SetReturnUrl(_search, _trackId);

            if (string.IsNullOrEmpty(_search))
            {
                return(RedirectToAction("Index", "Home"));
            }

            Token token = _tokenService.GetToken();

            if (string.IsNullOrEmpty(token.AccessToken) && !string.IsNullOrEmpty(token.RefreshToken))
            {
                string oldRefreshToken = token.RefreshToken;
                token = RefreshToken(token.RefreshToken, Constants.ClientSecret);
                token.RefreshToken = oldRefreshToken;
                _tokenService.SetToken(token);
            }
            else if (string.IsNullOrEmpty(token.AccessToken) && string.IsNullOrEmpty(token.RefreshToken))
            {
                Session["returnUrl"] = "~/Search?q=" + q + "&t=" + t;
                return(RedirectToAction("Index", "Authorize"));
            }

            SearchItem searchItem = Search(_search, token);

            PrivateProfile profile = GetMe(token);

            if (profile.Id == null && token.RefreshToken != null)
            {
                string oldRefreshToken = token.RefreshToken;
                token = RefreshToken(token.RefreshToken, Constants.ClientSecret);
                token.RefreshToken = oldRefreshToken;
                _tokenService.SetToken(token);
                profile = GetMe(token);
            }
            SearchResult result = new SearchResult()
            {
                SearchItem = searchItem,
                query      = _search,
                track      = _trackId,
                Profile    = profile,
            };

            if (profile.Id != null)
            {
                result.Playlists = GetPlaylists(token, profile.Id);
                if (result.Playlists.Items.Count == 0)
                {
                    FullPlaylist fullPlaylist = _paradifyService.CreatePlaylist(profile.Id, "Paradify Playlist", token);

                    if (!string.IsNullOrEmpty(fullPlaylist.Id))
                    {
                        result.Playlists = GetPlaylists(token, profile.Id);
                    }
                }
            }


            _userService.AddUser(profile);

            _historyService.AddSearchHistory(_search, _trackId, profile.Id, AppSource.WebSite);

            return(View(result));
        }