Exemplo n.º 1
0
        private void Submit_Clicked(object sender, EventArgs e)
        {
            Submit.IsEnabled = false;
            int CarrierID = 0;

            OMGITWebServices.OMGNotifyUserOptInSettings settings = new OMGITWebServices.OMGNotifyUserOptInSettings();



            string selCarrier = (string)PhoneCarrierPicker.Items[PhoneCarrierPicker.SelectedIndex];

            foreach (KeyValuePair <int, OMGITWebServices.OMGNotifyCarrierTextMapping> entry in CarrierTextMappings)
            {
                if (entry.Value.CarrierDisplayName == selCarrier)
                {
                    CarrierID = entry.Key;
                }
            }

            settings.CarrierID = CarrierID;
            try
            {
                settings.CellPhoneNumber = CellPhoneEntry.Text.Trim();
                settings.EmailAddress    = EmailEntry.Text.Trim();
                if (AllowEmailSwitch.IsToggled)
                {
                    settings.EmailOK = 1;
                }
                if (AllowTextMessageSwitch.IsToggled)
                {
                    settings.TextMessagingOK = 1;
                }
                settings.UserName = GlobalData.loginData.UserName;
            }
            catch (Exception ex) {; }

            if (settings.CellPhoneNumber == string.Empty && settings.TextMessagingOK == 1)
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    ErrorMessage.Text = "Information was not updated. You must enter a phone number if you select to receive text message notifications.";
                    ErrorLayout.Children.Add(ErrorMessage);
                    ErrorLayout.Children.Add(ReturnButton);
                    this.Content = ErrorLayout;
                });
                return;
            }

            if (settings.EmailAddress == string.Empty && settings.EmailOK == 1)
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    ErrorMessage.Text = "Information was not updated. You must enter an email address if you select to receive email notifications.";
                    ErrorLayout.Children.Add(ErrorMessage);
                    ErrorLayout.Children.Add(ReturnButton);
                    this.Content = ErrorLayout;
                });
                return;
            }

            List <int> UserClinicIDs = new List <int>();

            foreach (StackLayout s in AllClinicsLayout.Children)
            {
                var curClinicName = s.Children[1] as Label;
                var curID         = s.Children[2] as Label;
                var curSwitch     = s.Children[0] as Switch;
                if (curSwitch.IsToggled)
                {
                    try
                    {
                        UserClinicIDs.Add(Int32.Parse(curID.Text));
                    }
                    catch (Exception ex) {; }
                }
            }

            if (UserClinicIDs.Count == 0)
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    ErrorMessage.Text = "Information was not updated. You must select at least one clinic to receive notifications for.";
                    ErrorLayout.Children.Add(ErrorMessage);
                    ErrorLayout.Children.Add(ReturnButton);
                    this.Content = ErrorLayout;
                });
                return;
            }

            _client.DeleteAllUserClinicForNotificationsCompleted += ClientDeleteAllUserClinicForNotificationsCompleted;
            _client.DeleteAllUserClinicForNotificationsAsync(GlobalData.loginData);

            while (!doneDelete)
            {
                continue;
            }



            _client.AddUpdateUserOptInSettingsCompleted += ClientAddUpdateUserOptInSettingsCompleted;
            _client.AddUpdateUserOptInSettingsAsync(settings, GlobalData.loginData);

            while (addUpdateComplete == -1)
            {
                continue;
            }

            _client.AddUserClinicForNotificationsCompleted += ClientAddUserClinicForNotificationsCompleted;
            _client.AddUserClinicForNotificationsAsync(UserClinicIDs.ToArray(), GlobalData.loginData);

            while (addClinicComplete == -1)
            {
                continue;
            }

            Device.BeginInvokeOnMainThread(() =>
            {
                Navigation.PushAsync(new TestSendPage());
            });
        }