Exemplo n.º 1
0
        public async void Start(object hint = null)
        {
            _firebaseService.InitializeToken();
            UserData user = null;
            await Task.Run(() =>
            {
                lock (Settings.ApplicationData.DataBaseLock)
                {
                    using (var dbContext = new SettingsDbContext())
                    {
                        dbContext.Database.EnsureCreated();
                        user = dbContext.UserDatas.FirstOrDefault(u => u.IsLogedIn);
                        if (user != null)
                        {
                            dbContext.Entry(user).Collection(s => s.SearchHistories).Query().Take(15).Load();
                        }
                    }
                }
            });

            if (user != null)
            {
                Settings.ApplicationData.AreNotificationsOn = user.AreNotificationsOn;
                Settings.ApplicationData.RefreshToken       = user.RefreshToken;
                Settings.ApplicationData.UserData           = user;
                var result = await _authService.Login();

                if (result.Success)
                {
                    if (result.Success)
                    {
                        if (result.Result == ApplicationUserType.Admin)
                        {
                            await _navigationService.Navigate <AdminMainViewModel>();

                            return;
                        }
                        await _navigationService.Navigate <MainViewModel>();

                        return;
                    }
                }
                await _navigationService.Navigate <LoginViewModel>();

                return;
            }
            await _navigationService.Navigate <LoginViewModel>();
        }
Exemplo n.º 2
0
 public async Task Logout()
 {
     if (Settings.ApplicationData.CurrentUserViewModel != null &&
         Settings.ApplicationData.AreNotificationsOn)
     {
         _firebaseService.Unsubscribe();
     }
     Settings.ApplicationData.CurrentUserViewModel  = null;
     Settings.ApplicationData.CurrentAdminViewModel = null;
     Settings.ApplicationData.AccessToken           = string.Empty;
     Settings.ApplicationData.RefreshToken          = string.Empty;
     Settings.ApplicationData.UserData.IsLogedIn    = false;
     await Task.Run(() =>
     {
         lock (Settings.ApplicationData.DataBaseLock)
         {
             using (var dbContext = new SettingsDbContext())
             {
                 dbContext.Entry(Settings.ApplicationData.UserData).State = EntityState.Modified;
                 dbContext.SaveChanges();
             }
         }
     });
 }