Esempio n. 1
0
        /// <summary>
        /// Konstruktor
        /// </summary>
        /// <param name="nav"></param>
        /// <param name="events"></param>
        /// <param name="sync"></param>
        public BettrFitDataSource()
        {
            _sync = new SyncDataViewModel();
            Server = "https://www.bettrfit.com";
            UserData = new UserVM();
            UserGoals = new ObservableCollection<UserGoalVM>();
            Auth = new WebAccess.ServiceReference.AuthData();
            UserDaily = new ObservableCollection<UserDailyVM>();
            NutritionPlanFavorites = new ObservableCollection<NutritionPlanFavoriteVM>();
            NutritionPlanLeb = new ObservableCollection<LebensmittelVM>();
            SummaryConsumedDaytime = new WebAccess.ServiceReference.SummaryData();
            SummaryConsumedDay = new WebAccess.ServiceReference.SummaryData();

            _messenger = Mvx.Resolve<IMvxMessenger>();
            _mapper = new InitMapper();

            _messenger.Subscribe<NetworkEvent>(m => IsNetworkAvailable = m.IsAvailable);

            LoadAll();

            CheckLogin();
            //if (ret == 0)
            //{
            //    _EventAggregator = Container.Resolve<IEventAggregator>();
            //    _EventAggregator.GetEvent<LoggedInEvent>().Publish(true);
            //    _ds._loggedIn = true;
            //}
        }
Esempio n. 2
0
        public async Task<int> RegisterNewUser(WebAccess.ServiceReference.RegistrationItem vm)
        {
            _sync.BeginSync();
            try
            {
                var reg = await WebClientAsyncExtensions.RegisterNewUserTask(vm);

                if (reg == 0)
                {
                    var a = new WebAccess.ServiceReference.AuthData();
                    a.Username = vm.Email;
                    a.Password = vm.Pwd1;
                    a.ProviderId = 0;
                    var t = await WebClientAsyncExtensions.AuthenticateUserTask(a);

                    if (t != null)
                    {
                        Auth = t;
                        Auth.Username = vm.Email;
                        //_EventAggregator.GetEvent<LoggedInEvent>().Publish(true);

                        await LoggedIn();
                        _sync.EndSync();
                        return 0;
                    }
                    else
                    {
                        _messenger.Publish<LoggedInEvent>(new LoggedInEvent(this, false));
                        _sync.EndSync();
                        return -2;
                    }
                }
                else
                {
                    _messenger.Publish<LoggedInEvent>(new LoggedInEvent(this, false));
                    _sync.EndSync();
                    return reg;
                }
            }
            catch (Exception ex)
            {
                _sync.EndSync();
                return -3;
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Gives back the valid Auth Token used to communicate with WebService.
 /// </summary>
 /// <returns></returns>
 public WebAccess.ServiceReference.AuthData getAuth()
 {
     var auth = new WebAccess.ServiceReference.AuthData();
     auth.AuthenticatedToken = Auth.AuthenticatedToken;
     auth.Username = Auth.Username;
     return auth;
 }