Exemple #1
0
        private void buttonSaveChanges_Click(object sender, RoutedEventArgs e)
        {
            ErrorBucket errors = new ErrorBucket();
            string      name   = this.textName.Text.Trim();

            if (string.IsNullOrEmpty(name))
            {
                errors.Add("Name is required.");
            }
            string url = this.textUrl.Text.Trim();

            if (string.IsNullOrEmpty(url))
            {
                errors.Add("URL is required.");
            }

            // ok?
            if (!(errors.HasErrors))
            {
                // set...
                if (Bookmark == null)
                {
                    throw new InvalidOperationException("'Bookmark' is null.");
                }
                this.Bookmark.Name = name;
                this.Bookmark.Url  = url;

                // set...
                this.Bookmark.IsLocalModified = true;
                this.Bookmark.IsLocalDeleted  = false;

                // save...
                this.Bookmark.SaveChanges();

                // back...
                NavigationService.Navigate(new Uri("/ConfigurePage.xaml", UriKind.RelativeOrAbsolute));
            }

            // show...
            if (errors.HasErrors)
            {
                Alert.Show(this, errors.GetAllErrorsSeparatedByCrLf());
            }
        }
        private void DoLogon()
        {
            // validate...
            ErrorBucket bucket   = new ErrorBucket();
            string      username = this.textUsername.Text.Trim();

            if (string.IsNullOrEmpty(username))
            {
                bucket.Add("Username is required.");
            }
            string password = this.textPassword.Password.Trim();

            if (string.IsNullOrEmpty(password))
            {
                bucket.Add("Password is required.");
            }

            // error?
            if (bucket.HasErrors)
            {
                Alert.Show(this, bucket.GetAllErrorsSeparatedByCrLf());
                return;
            }

            // clear the credentials...
            this.ClearCredentials();

            // logon...
            UsersService users = new UsersService();

            users.Logon(username, password, delegate(LogonResponse response)
            {
                // we managed to get a response...
                if (response.Result == LogonResult.LogonOk)
                {
                    // we did it...
                    this.LogonOk();
                }
                else
                {
                    Alert.Show(this, response.Message);
                }
            }, Alert.GetFailedHandler(this));
        }