Beispiel #1
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            window = new UIWindow(UIScreen.MainScreen.Bounds);

            AppSettings.SetDefaultSettingsValue();

            BusinessModel.ConnectionString.SetDBPath(GetDatabaseFilePath());
            BusinessModel.Repository.Instance.InitializeDb();


            if (AppSettings.PersistentLogin && AppSettings.LoggedInLoginName != null && AppSettings.LoggedInLoginName != "")
            {
                BusinessModel.User _loggedInUser = BusinessModel.User.GetUserByLoginName(AppSettings.LoggedInLoginName);
                AppSession.LoggedInUser   = _loggedInUser;
                m_flyoutMenuController    = new OasisFlyoutController();
                window.RootViewController = m_flyoutMenuController;
                window.MakeKeyAndVisible();
                BTProgressHUD.Show("Synching Account");
                bool _dataUpdateSuccessful = false;
                Task.Factory.StartNew(() => {
                    string responseString = "";
                    try{
                        WebClient service = new WebClient();
                        service.Headers.Add(HttpRequestHeader.Accept, "application/json");
                        string serviceURL = AppConfig.BaseWebserviceURL +
                                            "UserByLoginName/" +
                                            System.Web.HttpUtility.UrlEncode(AppSettings.LoggedInLoginName);
                        responseString = service.DownloadString(serviceURL);

                        if (responseString != null && responseString != "")
                        {
                            var _jsonUser = System.Json.JsonValue.Parse(responseString);

                            _loggedInUser = BusinessModel.User.GetUserByMainSystemID(_jsonUser ["UserID"]);
                            if (_loggedInUser == null)
                            {
                                _loggedInUser = new BusinessModel.User();
                                _loggedInUser.MainSystemID = _jsonUser ["UserID"];
                            }
                            _loggedInUser.LoginName     = _jsonUser ["LoginName"];
                            _loggedInUser.UserName      = _jsonUser ["UserName"];
                            _loggedInUser.Password      = _jsonUser ["Password"];
                            _loggedInUser.EmailAddress  = _jsonUser ["UserEmail"];
                            _loggedInUser.LastLoginDate = DateTime.Now;
                            _loggedInUser.Save();
                            AppSession.LoggedInUser = _loggedInUser;
                            SyncManager.PushAllDoSyncData();
                            SyncManager.SyncUserExamDataFromServer(AppSession.LoggedInUser);
                            SyncManager.SyncUserExamAccess(AppSession.LoggedInUser);
                            _dataUpdateSuccessful = true;
                        }
                        else
                        {
                            //The user is not found, so we present login view
                            AppSettings.LoggedInLoginName = null;
                            InvokeOnMainThread(() => {
                                LoginView _loginViewController            = new LoginView();
                                _loginViewController.ModalInPopover       = false;
                                _loginViewController.ModalTransitionStyle = UIModalTransitionStyle.FlipHorizontal;
                                m_flyoutMenuController.PresentViewController(_loginViewController, false, null);
                            });
                        }
                    }
                    catch (Exception ex) {
                        Console.WriteLine(ex.ToString());
                    }
                }).ContinueWith(task1 => {
                    BTProgressHUD.Dismiss();

                    if (_dataUpdateSuccessful)
                    {
                        UIViewController _currentDisplayedController = m_flyoutMenuController.ExamTab.VisibleViewController;
                        if (_currentDisplayedController.GetType() == typeof(ExamListView))
                        {
                            ((ExamListView)_currentDisplayedController).LoadExamList();
                        }
                    }

                    StartSyncThread();
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
            else
            {
                m_flyoutMenuController    = new OasisFlyoutController();
                window.RootViewController = m_flyoutMenuController;
                window.MakeKeyAndVisible();
                LoginView _loginViewController = new LoginView();
                _loginViewController.ModalInPopover       = false;
                _loginViewController.ModalTransitionStyle = UIModalTransitionStyle.FlipHorizontal;
                m_flyoutMenuController.PresentViewController(_loginViewController, false, null);
                StartSyncThread();
            }

//			m_flyoutMenuController = new OasisFlyoutController ();
//			window.RootViewController =  m_flyoutMenuController;
//			window.MakeKeyAndVisible ();
//			LoginView _loginViewController = new LoginView ();
//			_loginViewController.ModalInPopover = false;
//			_loginViewController.ModalTransitionStyle = UIModalTransitionStyle.FlipHorizontal;
//			m_flyoutMenuController.PresentViewController (_loginViewController, false, null);
//			StartSyncThread ();
//
            return(true);
        }
        private void ProcessLogin()
        {
            if (txtUserName.Text != null && txtPassword.Text != null &&
                txtUserName.Text != "" && txtPassword.Text != "")
            {
                //Clear the session just in case there is leftover session
                AppSession.ClearSession();
                if (Reachability.InternetConnectionStatus() == NetworkStatus.NotReachable)
                {
                    //Not reachable, tell user to try again later
                    UIAlertView _alert = new UIAlertView("No Connection", "Please connect to the internet to login", null, "Ok", null);
                    _alert.Show();
                    return;
                }

                //If network is reachable, login
                BTProgressHUD.Show("Please wait");
                bool   _loginSuccessful  = false;
                bool   _serviceReachable = true;
                string userName          = txtUserName.Text;
                string password          = txtPassword.Text;

                Task.Factory.StartNew(() => {
                    string responseString = "";
                    try{
                        WebClient service = new WebClient();
                        service.Headers.Add(HttpRequestHeader.Accept, "application/json");
                        string serviceURL = AppConfig.BaseWebserviceURL +
                                            "UserByLoginNameAndPassword/" +
                                            System.Web.HttpUtility.UrlEncode(userName) + "/" +
                                            System.Web.HttpUtility.UrlEncode(password);
                        responseString = service.DownloadString(serviceURL);

                        if (responseString != null && responseString != "")
                        {
                            var _jsonUser = System.Json.JsonValue.Parse(responseString);
                            BusinessModel.User _loggedInUser;
                            _loggedInUser = BusinessModel.User.GetUserByMainSystemID(_jsonUser ["UserID"]);
                            if (_loggedInUser == null)
                            {
                                _loggedInUser = new BusinessModel.User();
                                _loggedInUser.MainSystemID = _jsonUser ["UserID"];
                            }
                            _loggedInUser.LoginName     = _jsonUser ["LoginName"];
                            _loggedInUser.UserName      = _jsonUser ["UserName"];
                            _loggedInUser.Password      = _jsonUser ["Password"];
                            _loggedInUser.EmailAddress  = _jsonUser ["UserEmail"];
                            _loggedInUser.LastLoginDate = DateTime.Now;
                            _loggedInUser.Save();
                            _loginSuccessful        = true;
                            AppSession.LoggedInUser = _loggedInUser;
                            SyncManager.PushAllDoSyncData();
                            int _examCount = BusinessModel.SQL.ExecuteScalar <int> ("SELECT COUNT(*) FROM tblExam", new object[] {});
                            if (_examCount == 0)
                            {
                                //Only sync if there is not exam for now
                                try{
                                    SyncManager.SyncExamDataFromServer();
                                }catch (Exception ex) {
                                    Console.WriteLine("Exception on synching exam data from server");
                                    Console.WriteLine(ex.ToString());
                                    throw ex;
                                }
                            }

                            try{
                                SyncManager.SyncUserExamDataFromServer(AppSession.LoggedInUser);
                            }catch (Exception ex) {
                                Console.WriteLine("Exception on synching user exam data from server");
                                Console.WriteLine(ex.ToString());
                                throw ex;
                            }

                            try{
                                SyncManager.SyncUserExamAccess(AppSession.LoggedInUser);
                            }catch (Exception ex) {
                                Console.WriteLine("Exception on synching user exam access data from server");
                                Console.WriteLine(ex.ToString());
                                throw ex;
                            }
                        }
                        else
                        {
                            _loginSuccessful = false;
                        }
                    }
                    catch (Exception ex) {
                        Console.WriteLine("Unable to login as the service encountered an error for username: "******"Invalid Credential", "The credential you entered is invalid, please try again", null, "Ok", null);
                            _invalidCredentialAlert.Show();
                        }
                        else
                        {
                            UIAlertView _alert = new UIAlertView("Service Unavailable", "We could not contact login server to verify your credential. Please try again later", null, "Ok", null);
                            _alert.Show();
                        }
                    }
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
            else
            {
                UIAlertView _requiredFieldAlert = new UIAlertView("Credential Required", "Please enter your credential in the provided field", null, "Ok", null);
                _requiredFieldAlert.Show();
            }
        }
Beispiel #3
0
        //
        // GET: /User/Create

        public ActionResult Create(BusinessModel.User user)
        {
            BusinessServices.UserService.InsertUser(user);
            return(View());
        }