Beispiel #1
0
        private async void btnSave_Clicked(object sender, EventArgs e)
        {
            if (!validate())
            {
                await DisplayAlert("Validation Error", "All fields are are required.", "Ok");

                return;
            }

            try
            {
                await client.AddPersonAsync(person);
                await DisplayAlert("Success", "Data has been saved.", "Ok");

                Clear();
            }
            catch (Exception ex)
            {
                tbxFirstName.Text   = string.Empty;
                tbxLastName.Text    = string.Empty;
                tbxPhoneNumber.Text = string.Empty;
                imgPhoto.Source     = null;
                person = new Person();
            }
        }
        private void IntializeEvents()
        {
            btnSave.Clicked += async(object sender, EventArgs e) =>
            {
                if (!Validate())
                {
                    await DisplayAlert("Validation Error", "First name, last name, phone number and picture are required.", "Ok");

                    return;
                }

                try
                {
                    await client.AddPersonAsync(person);
                    await DisplayAlert("Success", "Data has been saved.", "Ok");
                }
                catch (Exception ex)
                {
                    await DisplayAlert("Error", ex.Message, "Ok");
                }
            };

            btnCamera.Clicked += async(object sender, EventArgs e) =>
            {
                var photo = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                });

                if (photo != null)
                {
                    imgPhoto.Source = ImageSource.FromStream(() => photo.GetStream());
                    byte[] bytes;
                    using (var memoryStream = new MemoryStream())
                    {
                        photo.GetStream().CopyTo(memoryStream);
                        bytes = memoryStream.ToArray();
                    }

                    string base64 = Convert.ToBase64String(bytes);
                    person.PictureBase64 = base64;
                }
            };

            entFirstName.TextChanged += (object sender, TextChangedEventArgs e) =>
            {
                person.FirstName = e.NewTextValue;
            };

            entLastName.TextChanged += (object sender, TextChangedEventArgs e) =>
            {
                person.LastName = e.NewTextValue;
            };

            entPhoneNumber.TextChanged += (object sender, TextChangedEventArgs e) =>
            {
                person.PhoneNumber = e.NewTextValue;
            };
        }
Beispiel #3
0
        private async void btnSave_Clicked(object sender, EventArgs e)
        {
            if (!Validate())
            {
                await DisplayAlert("Validation Error", "First name, last name, phone number and picture are required.", "Ok");

                return;
            }

            try
            {
                await client.AddPersonAsync(person);
                await DisplayAlert("Success", "Data has been saved.", "Ok");

                Clear();
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error", ex.Message, "Ok");
            }
        }