Beispiel #1
0
        /// <summary>
        /// Update strava athlete details
        /// </summary>
        /// <param name="token">Strava access token</param>
        public bool UpdateAthlete(string token)
        {
            try
            {
                stravaAthleteDetails = _client.Athletes.GetAthlete();

                fitnessViewerAthlete = _unitOfWork.CRUDRepository.GetByKey <Athlete>(this._stravaId);

                if (fitnessViewerAthlete == null)
                {
                    return(false);
                }

                LogActivity("Updating Athlete", fitnessViewerAthlete);

                // update athlete details from strava.
                Mapper.Map(stravaAthleteDetails, fitnessViewerAthlete);

                // get latest access token.
                fitnessViewerAthlete.Token = token;

                _unitOfWork.CRUDRepository.Update <Athlete>(fitnessViewerAthlete);

                UpdateUserConfig();

                _unitOfWork.Complete();

                return(true);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Add strava athlete details to data
        /// </summary>
        /// <param name="userId">Indentity userId</param>
        /// <param name="token">Strava access token</param>
        public void AddAthlete(string userId, string token, string refreshToken, int expiresAt, int expiresIn)
        {
            _userId = userId;
            base.SetupClient(token, refreshToken, expiresAt, expiresIn);
            stravaAthleteDetails = _client.Athletes.GetAthlete();

            fitnessViewerAthlete              = Mapper.Map <Athlete>(stravaAthleteDetails);
            fitnessViewerAthlete.UserId       = userId;
            fitnessViewerAthlete.Token        = token;
            fitnessViewerAthlete.RefreshToken = refreshToken;
            fitnessViewerAthlete.ExpiresAt    = expiresAt;
            fitnessViewerAthlete.ExpiresIn    = expiresIn;

            _unitOfWork.CRUDRepository.Add <Athlete>(fitnessViewerAthlete);

            //UpdateUserConfig();

            // add user to the strava download queue for background downloading of activities.
            DownloadQueue.CreateQueueJob(userId, enums.DownloadType.Strava).Save();

            _unitOfWork.Complete();

            UpdateUserConfig();
        }