public async Task<UserInformations> GetUserInformations() { if (_userInformations == null) { try { var res = await _storageService.GetUserInformations(); if (!string.IsNullOrEmpty(res)) { var ui = JsonConvert.DeserializeObject<UserInformations>(res); var beers = await _storageService.GetUserBeers(); if (!string.IsNullOrEmpty(beers)) ui.Beers = JsonConvert.DeserializeObject<ObservableCollection<Beer>>(beers); _userInformations = ui; } } catch (Exception ex) { LogHelper.Instance.LogException(ex, this); } } if (_userInformations == null) _userInformations = await CreateNewUser(); return _userInformations; }
private async Task<UserInformations> CreateNewUser() { var newui = new UserInformations() { Guid = Guid.NewGuid(), FirstTime = true }; var str = JsonConvert.SerializeObject(newui); if (!await _storageService.SetUserInformations(str)) LogHelper.Instance.Log(LogLevel.FatalError, "Cannot save User Informations", this); return newui; }
public async Task<bool> SyncUserInformations(UserInformations userInformations) { try { var drinkerInfo = RequestConverter.Instance.ConvertToDrinkerRequest(userInformations.Guid, PossibleActions.Update, userInformations); return (await _dataService.PostDrinker(drinkerInfo)).IsSuccessfull; } catch (Exception ex) { LogHelper.Instance.LogException(ex, this); } return false; }
private async void Initialize() { UserInfo = await _settingsRepository.GetUserInformations(); var colorsJson = await _storageService.GetAssetFile(AssetFileKeys.ColorsJson); Colors = JsonConvert.DeserializeObject<ObservableCollection<Color>>(colorsJson); SelectedColor = Colors.FirstOrDefault(c => c.ColorValue == UserInfo.Color); if (SelectedColor == null) { var rand = new Random(DateTime.Now.Millisecond); SelectedColor = Colors[rand.Next(0, Colors.Count - 1)]; } Name = UserInfo.Name; }
public async Task<bool> SaveUserInformations(UserInformations userInformations) { try { _userInformations = userInformations; var settings = JsonConvert.SerializeObject(userInformations); var beers = JsonConvert.SerializeObject(userInformations.Beers); return await _storageService.SetUserInformations(settings) && await _storageService.SetUserBeers(beers); } catch (Exception ex) { LogHelper.Instance.LogException(ex, this); } return false; }
private ObservableCollection<DrinkerCycle> ConstructBusinessModel(List<Drinker> drinkers, List<DrinkerCycle> drinkerCycles, UserInformations infos) { foreach (var drinker in drinkers) { foreach (var authDrinkerCycle in drinker.AuthDrinkerCycleGuids) { var authCircle = drinkerCycles.FirstOrDefault(ds => ds.Guid == authDrinkerCycle); if (authCircle != null) authCircle.AuthBeerDrinkers.Add(drinker); } foreach (var nonAuthDrinkerCycle in drinker.NonAuthDrinkerCycleGuids) { var nonAuthCircle = drinkerCycles.FirstOrDefault(ds => ds.Guid == nonAuthDrinkerCycle); if (nonAuthCircle != null) nonAuthCircle.NonAuthBeerDrinkers.Add(drinker); } } foreach (var drinkerCycle in drinkerCycles) { if (drinkerCycle.IsAuthenticated) drinkerCycle.AuthBeerDrinkers.Add(infos); else drinkerCycle.NonAuthBeerDrinkers.Add(infos); } return new ObservableCollection<DrinkerCycle>(drinkerCycles); }