Beispiel #1
0
        public void IsPatientValid_CheckPatientIsValid_PatientIsValid()
        {
            // Arrange
            var cpr = "0105921853";

            var loginManager = new LoginManager();

            try
            {
                // Act
                var loginCpr = loginManager.GetPatient(cpr);

                // Assert
                Assert.AreEqual(cpr, loginCpr);
            }
            catch (Exception e)
            {
                Assert.Fail("Status Code not OK " + e.Message);
            }

        }
        private void SetupLayout()
        {
            // Perform any additional setup after loading the view, typically from a nib.

            loginButton.TouchUpInside += (sender, e) =>
            {
                if (UserData.IsUserLoggedIn)
                {
                    LogOffUser();
                }
                else
                {
                    var userCprInput = userNameTextField.Text;
                    // If user cpr nr is valid
                    if (ValidateCpr(userCprInput))
                    {
                        new System.Threading.Thread(() =>
                        {
                            // Send cpr til web api for yderligere validering (er patient indlagt/udskrevet?)
                            // Hvis Response kode er OK betyder det er patient er indlagt og ikke udskrevet endnu
                       
                            try
                            {

                                // Skriv evt. en besked til bruger om at login gik OK
                                this.InvokeOnMainThread(() =>
                                {
                                    // Show the overlay (loading screen)
                                    AppDelegate.ShowLoadingScreen(this, Strings.SpinnerDataReading);
                                });

                                var manager = new LoginManager();
                                var cpr = manager.GetPatient(userCprInput);

                                if (cpr == null) throw new Exception(Strings.ErrorPatientNotValid);
                            }
                            // Response kode er forskellig fra OK, hvilket kan betyde en netværksfejl eller at patient ikke er indlagt (antager vi).
                            catch (Exception ex)
                            {
                                Console.WriteLine("Login failed with error: " + ex.Message);

                                this.InvokeOnMainThread(() =>
                                {
                                    // Hide the overlay (loading screen)
                                    AppDelegate.loadingOverlay.Hide();

                                    var errorMessage = ex.Message.Equals(Strings.ErrorPatientNotValid) ? Strings.ErrorPatientNotValid : Strings.ErrorNoNetwork;
            
                                    new UIAlertView(Strings.ErrorLogin, errorMessage, null, null, "OK").Show();
                                });

                                // Fortsæt ikke programmet, hvis login fejlede
                                return;
                            }
                            
                            // Hent kategorier for den pågældende patient/afdeling/sygehus
                            try
                            {
                                Categories = DataHandler.LoadCategoriesFromWeb();
                                //Categories = DataHandler.LoadCategoriesTESTDATA();

                                // Delete categories from web
                                DataHandler.DeleteCategoriesFromLocalDatabase(new LocalDB());

                                // If data loading from web not succeded, nothing will be saved to the local database (Categories instance will be null)
                                DataHandler.SaveCategoriesToLocalDatabase(new LocalDB(), Categories);
                            }
                            // Mislykkedes at hente kategorier fra web, indlæser fra lokal database (i næste view)
                            catch (Exception ex)
                            {
                                Console.WriteLine("ERROR loading data: " + ex.Message + "...loading from local database");

                                this.InvokeOnMainThread(() =>
                                {
                                    // Hide the overlay (loading screen)
                                    AppDelegate.loadingOverlay.Hide();

                                    new UIAlertView(Strings.Error, Strings.ErrorReading, null, Strings.OK, null).Show();
                                });
                            }

                            this.InvokeOnMainThread(() =>
                            {
                                // Login user
                                LoginInUser();

                                // Hide the overlay (loading screen)
                                AppDelegate.loadingOverlay.Hide();

                                // Go to valgmuligheder
                                GoToCategories();
                            });

                        }).Start();
                    }
                }

            };

            this.userNameTextField.ShouldReturn += (textField) =>
            {
                textField.ResignFirstResponder();
                return true;
            };
        }
Beispiel #3
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            InitializeLayout();

            CreateSQLiteTables();

            if (Intent.GetBooleanExtra("logoff", false))
            {
                LogOffUser();
            }

            btnLogin.Click += delegate
            {
                ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);

                var isLoggedIn = prefs.GetBoolean(LoginKey, false);

                if (isLoggedIn)
                {
                    LogOffUser();
                }
                else
                {
                    // If user login info is correct, show services
                    var userCprInput = etCprNr.Text;
                    if (ValidateCpr(userCprInput))
                    {
                        ThreadPool.QueueUserWorkItem(o =>
                        {
                            try
                            {
                                this.RunOnUiThread(() =>
                                {
                                    dialog = new ProgressDialog(this);
                                    dialog.SetMessage(Strings.SpinnerDataReading);
                                    dialog.SetCancelable(false);
                                    dialog.Show();
                                });

                                var manager = new LoginManager();
                                var cpr = manager.GetPatient(userCprInput);

                                if (cpr == null) throw new Exception(Strings.ErrorPatientNotValid);

                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Login failed with error: " + ex.Message);

                                this.RunOnUiThread(() =>
                                {
                                    dialog.Hide();

                                    var errorMessage = ex.Message.Equals(Strings.ErrorPatientNotValid) ? Strings.ErrorPatientNotValid : Strings.ErrorNoNetwork;

                                    new AlertDialog.Builder(this).SetTitle(Strings.ErrorLogin)
                                        .SetMessage(errorMessage)
                                        .SetPositiveButton("OK", delegate { })
                                        .Show();
                                });

                                return;
                            }

                            try
                            {
                                Categories = DataHandler.LoadCategoriesFromWeb();
                                DataHandler.DeleteCategoriesFromLocalDatabase(new LocalDB());
                                DataHandler.SaveCategoriesToLocalDatabase(new LocalDB(), Categories);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("ERROR loading data: " + ex.Message + "...loading from local database");

                                this.RunOnUiThread(() =>
                                {
                                    dialog.Hide();

                                    new AlertDialog.Builder(this).SetTitle(Strings.Error)
                                        .SetMessage(Strings.ErrorReading)
                                        .SetPositiveButton("OK", delegate { })
                                        .Show();
                                });
                            }

                            this.RunOnUiThread(() =>
                            {
                                LoginInUser();

                                dialog.Hide();

                                // Go to valgmuligheder
                                GoToCategories();
                            });

                        });

                        
                    }
                }
            };
        }
Beispiel #4
0
        internal bool ValidateLogin()
        {
            var userinput = userNameTextBox.Text;
            // If textfield are not empty
            if (userinput != "")
            {
                // CPR VALIDERING HER

                // PATIENT VALIDERING HER
                var manager = new LoginManager();
                var cpr = manager.GetPatient(userinput);

                if (cpr == null)
                {
                    throw new Exception(Strings.ErrorPatientNotValid);
                }

                return true;
            }

            return false;
        }