private async void SaveButton_Click(object sender, EventArgs e)
        {
            DisableErrors();
            if (!CheckInput()) return;

            if (!txtPassword.Password.Equals(txtRepeatPassword.Password))
            {
                MessageBox.Show("The password doesn't match!");
                return;
            }

            var error = false;
            try
            {
                var existingUser = (await Service.GetTable<User>()
                    .Where(t => t.Id == App.User.Id).ToListAsync()).FirstOrDefault();
                existingUser.Password = txtPassword.Password;
                existingUser.Fullname = txtName.Text;
                existingUser.Email = txtEmail.Text;
                existingUser.Address = txtAddress.Text;
                existingUser.PhoneNumber = txtPhone.Text;
                existingUser.Type = (cmbUserType.SelectedItem as NameType).Type;
                await Service.UpdateItemAsync(existingUser);
                App.User = existingUser;

                var settings = new SettingsHelper();
                if (settings.GetRememberMeFromSettings())
                {
                    settings.SetPasswordToSettings(existingUser.Password);
                }
            }
            catch (Exception ex)
            {
                error = true;
            }

            if (error)
            {
                MessageBox.Show("Something went wrong!");
                return;
            }

            if (NavigationService.CanGoBack)
                NavigationService.GoBack();
        }
Exemplo n.º 2
0
        private async Task Login(string username, string password, bool rememberMe)
        {
            ActivateLoading();

            var error = false;
            User user = null;
            try
            {
                user = (await Service.GetTable<User>()
                    .Where(t => t.Username == username && t.Password == password).ToListAsync()).FirstOrDefault();
            }
            catch (Exception ex)
            {
                error = true;
            }

            if (error)
            {
                MessageBox.Show("Something went wrong!");
                return;
            }
            if (user == null)
            {
                MessageBox.Show("The username, password combination does not match!");
                return;
            }

            App.User = user;

            if (rememberMe)
            {
                var settings = new SettingsHelper();
                settings.SetUsernameToSettings(username);
                settings.SetPasswordToSettings(password);
                settings.SetRememberMeToSettings(true);
            }

            Uri uri = null;
            switch (user.Type)
            {
                case UserType.Volunteer:
                    uri = new Uri(PageConstants.MainPage, UriKind.RelativeOrAbsolute);
                    break;
                case UserType.Medic:
                    uri = new Uri(PageConstants.MainPage, UriKind.RelativeOrAbsolute);
                    break;
                case UserType.Manager:
                    uri = new Uri(PageConstants.MainPage, UriKind.RelativeOrAbsolute);
                    break;
            }
            NavigationService.Navigate(uri);
        }