Exemple #1
0
        private Task LoginAsync()
        {
            return Task.Factory.StartNew(() =>
            {
                CommandExecuting = true;
                //Try to signin
                WebApiClient client;
                try
                {
                    client = new WebApiClient(@AppUrl, Login, Password);
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message);
                    return false;
                }

                try
                {
                    //Initialize DataContext with Url and Access token
                    CaffeDataContext.InitializeContext(@AppUrl + @"/CaffeDataService.svc", client.Token);

                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message);
                    return false;
                }

                var userModel = client.GetUserInfo();

                if (userModel.Role == UserRoles.Manager.ToString())
                {
                    _hostPage.Dispatcher.Invoke(() => _hostPage.NavigationService.Navigate(new ManagerMainPage(userModel)));
                }
                if (userModel.Role == UserRoles.Cashier.ToString())
                {
                    _hostPage.Dispatcher.Invoke(() => _hostPage.NavigationService.Navigate(new CashierMainPage(userModel)));
                }
                if (userModel.Role == UserRoles.SuperUser.ToString())
                {
                    _hostPage.Dispatcher.Invoke(() => _hostPage.NavigationService.Navigate(new SuperuserMainPage(userModel)));
                }
                return true;
            }).ContinueWith((result) => CommandExecuting = false);
        }