Beispiel #1
0
        public ActionResult Index(string q)
        {
            _search  = q;
            _trackId = "";

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

            Token token = ViewBag.Token;

            if (string.IsNullOrEmpty(token.AccessToken) && string.IsNullOrEmpty(token.RefreshToken))
            {
                _sessionService.SetReturnUrl("~/" + RouteData.Values["controller"] + "?q=" + _search);

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

            PrivateProfile profile = _userService.GetMe(_tokenCookieService);

            if (profile.IsNotAuthorized())
            {
                return(RedirectToAction("Index", "Authorize"));
            }

            SearchItem searchItem = Search(_search, token);

            if (searchItem.IsNotAuthorized())
            {
                return(RedirectToAction("Index", "Authorize"));
            }
            SearchResult result = new SearchResult()
            {
                SearchItem = searchItem,
                query      = _search,
                track      = _trackId,
            };

            if (profile.Id != null)
            {
                _historyService.AddSearchHistory(_search, _trackId, profile.Id, AppSource.WebSite);
            }

            return(View("Index2", result));
        }
Beispiel #2
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));
        }