コード例 #1
0
        public async Task <ActionResult> AddAccessToken()
        {
            // First, delete the current token
            // TODO: Refactor so that it goes via ID
            DeleteToken();

            // Get a new token via Spotify API
            var code             = GetCodeFromHttpContext();
            var tokenFromRepoDto = await _spotifyService.GetAccessTokenFromSpotify(code);

            var tokenEntityToSave = _mapper.Map <Repository.Data.Entities.AccessToken>(tokenFromRepoDto);

            tokenEntityToSave.DateModified = DateTime.Now;

            // Store token
            await _accessTokenRepository.AddAccessToken(tokenEntityToSave);

            try
            {
                await _accessTokenRepository.SaveAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError("Adding an access token failed on save.", ex);
            }

            return(Ok());
        }