private async Task <bool> RetreiveOnlineUserInfoAsync()
        {
            bool result = false;

            try
            {
                var userInfoKey = new UserInfoKey(); // no need userId here
                var userInfo    = await UserInfoWebService.GetUserInfoAsync(userInfoKey);

                if (userInfo != null)
                {
                    var dbContext       = Resolver.Resolve <ISQLite>().GetConnection();
                    var userInfoService = new UserInfoService(dbContext);
                    var userInfoList    = userInfoService.FindUserInfos();
                    if (userInfoList != null && userInfoList.Count > 0)
                    { // delete old userInfo
                        var userInfoKeyList = new List <UserInfoKey>();
                        foreach (var key in userInfoList)
                        {
                            userInfoKeyList.Add(key);
                        }
                        userInfoService.DeleteUserInfoList(userInfoKeyList);
                    }
                    userInfoService.UpdateUserInfo(userInfo);
                    UserData.Instance.UserInfo = userInfo;
                    _userId = userInfo.UserId;
                    result  = true;
                }
            }
            catch (Exception except)
            {
            }
            return(result);
        }
Esempio n. 2
0
        private async Task SynchronizeDataAsync()
        {
            if (!string.IsNullOrWhiteSpace(_userId))
            {
                BindingUserInfo.UserInfo = _userInfo;
                if (_userInfo != null)
                {
                    var user = await UserInfoWebService.GetUserAsync(_userId);

                    if (user != null)
                    {
                        BindingUserInfo.Name  = user.Name;
                        BindingUserInfo.Email = user.Email;
                    }
                }
                BindingUserInfo.Sex      = _userInfo.Sex;
                BindingUserInfo.Unit     = _userInfo.Unit;
                BindingUserInfo.ZipCode  = _userInfo.ZipCode;
                BindingUserInfo.CoutryId = _userInfo.CountryId;
                BindingUserInfo.Height   = _userInfo.Height;
                BindingUserInfo.Weight   = _userInfo.Weight;

                if (_countries != null && _countries.Count > 0)
                {
                    var country = _countries.Where(c => c.Id == _userInfo.CountryId).FirstOrDefault();
                    if (country != null)
                    {
                        BindingUserInfo.CountryName = country.Name;
                    }
                }
            }
        }
        private async Task <TUnitType> GetExerciseUnit()
        {
            TUnitType unit = TUnitType.Metric;

            try
            {
                if (_trainingExercise != null && _trainingExercise.TrainingExerciseSets != null &&
                    _trainingExercise.TrainingExerciseSets.Count > 0)
                {
                    unit = _trainingExercise.TrainingExerciseSets[0].Unit;
                }
                else
                {
                    if (_userInfo == null)
                    {
                        var userInfoKey = new UserInfoKey()
                        {
                            UserId = _trainingExercise.UserId
                        };
                        if (_trainingExercise.UserId == UserData.Instance.UserInfo.UserId)
                        {
                            var userInfoService = new UserInfoService(_dbContext);
                            _userInfo = userInfoService.GetUserInfo(userInfoKey);
                        }
                        else
                        {
                            _userInfo = await UserInfoWebService.GetUserInfoAsync(userInfoKey);
                        }
                    }
                    if (_userInfo != null)
                    {
                        unit = _userInfo.Unit;
                    }
                }
            }
            catch
            {
            }
            return(unit);
        }
Esempio n. 4
0
        private async Task <bool> SaveDataAsync()
        {
            var userInfo = new UserInfo()
            {
                UserId       = _userInfo.UserId,
                Sex          = BindingUserInfo.Sex,
                Unit         = BindingUserInfo.Unit,
                Height       = BindingUserInfo.Height,
                Weight       = BindingUserInfo.Weight,
                ZipCode      = BindingUserInfo.ZipCode,
                CountryId    = BindingUserInfo.CoutryId,
                TimeZoneName = _userInfo.TimeZoneName //not for mobile but need to transfer
            };

            userInfo = await UserInfoWebService.UpdateUserInfoAsync(userInfo);

            if (userInfo != null && userInfo.UserId == UserData.Instance.UserInfo.UserId)
            {
                _userInfoService.UpdateUserInfo(userInfo);
            }
            return(userInfo != null);
        }
Esempio n. 5
0
        private async Task <bool> PreLoadDataAsync()
        {
            bool result = false;

            try
            {
                var countryService = new CountryService(_dbContext);
                _countries = countryService.FindCountries();
                if (_countries == null || _countries.Count == 0)
                {
                    //find country in server if not present in database (this viewModel can be display directly after user login)
                    _countries = await CountryWebService.FindCountriesAsync();

                    //populate country in local database
                    if (_countries != null && _countries.Count > 0)
                    {
                        countryService.UpdateCountryList(_countries);
                    }
                }

                var userInfoKey = new UserInfoKey()
                {
                    UserId = _userId
                };
                _userInfo = await UserInfoWebService.GetUserInfoAsync(userInfoKey);

                if (_userInfo != null && _countries != null && _countries.Count > 0)
                {
                    result = true;
                }
            }
            catch
            {
            }
            return(result);
        }