Beispiel #1
0
        public async Task Initialize()
        {
            Characters.Clear();

            _account = await _helper.GetAccountAsync();

            if (_account != null)
            {
                var characters = await _repository.ReadAsync();

                foreach (var character in characters.Select(c => new CharacterViewModel(c)))
                {
                    Characters.Add(character);
                }
            }
        }
        public LogInPageViewModel(IAuthenticationHelper _helper, INavigationService _service, IUserAPI _userAPI)
        {
            helper  = _helper;
            service = _service;
            userAPI = _userAPI;

            //gets called when app starts
            InitCommand = new RelayCommand(async o =>
            {
                account = await helper.GetAccountAsync();
                if (account != null)
                {
                    //check api if user exists
                    var user = await userAPI.GetMyself();

                    //navigate to main page
                    if (user != null)
                    {
                        CommonAttributes.account = account;
                        service.Navigate(typeof(MainPage), null);
                    }
                    else
                    {
                        service.Navigate(typeof(RegisterPage), account);
                    }
                }
            });

            //gets called when log in button is pressed
            LogInCommand = new RelayCommand(async o =>
            {
                account = await helper.GetAccountAsync();
                //navigate to main page
                if (account == null)
                {
                    //pop up sign in page
                    account = await helper.SignInAsync();

                    //if sign in is successfull
                    if (account != null)
                    {
                        CommonAttributes.account = account;
                        //check api if user exists
                        var user = await userAPI.GetMyself();

                        if (user == null)
                        {
                            service.Navigate(typeof(RegisterPage), account);
                        }
                        else
                        {
                            service.Navigate(typeof(MainPage), null);
                        }
                    }
                }
                else
                {
                    CommonAttributes.account = account;
                    //check api if user exists
                    var user = await userAPI.GetMyself();

                    if (user == null)
                    {
                        service.Navigate(typeof(RegisterPage), account);
                    }
                    else
                    {
                        service.Navigate(typeof(MainPage), null);
                    }
                }
            });
        }