示例#1
0
        public async Task <PartyGoer> GetCurrentPartyGoerAsync()
        {
            string partyGoerId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (_partyGoerCache.ContainsKey(partyGoerId))
            {
                return(_partyGoerCache[partyGoerId]);
            }
            else
            {
                PartyGoerDetails partyGoerDetails = await _spotifyHttpClient.GetUserDetailsAsync(partyGoerId);

                PartyGoer newPartyGoer = new PartyGoer(partyGoerDetails);
                _partyGoerCache.Add(partyGoerId, newPartyGoer);

                return(newPartyGoer);
            }
        }
示例#2
0
        /// <summary>
        /// Accesses the current party goer. If no party goer is associated with the current session, null is returned
        /// </summary>
        /// <returns>A party goer, if unauthenticated, null</returns>
        public async Task <PartyGoer> GetCurrentPartyGoerAsync()
        {
            string partyGoerId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (string.IsNullOrWhiteSpace(partyGoerId))
            {
                return(null);
            }

            if (_partyGoerCache.ContainsKey(partyGoerId))
            {
                return(_partyGoerCache[partyGoerId]);
            }
            else
            {
                User user = await _spotifyHttpClient.GetUserDetailsAsync(partyGoerId);

                PartyGoer newPartyGoer = new PartyGoer(user.SpotifyId, user.ExplicitSettings.Filter, user.Market, user.Product);
                _partyGoerCache.TryAdd(partyGoerId, newPartyGoer);

                return(newPartyGoer);
            }
        }