Пример #1
0
        private void LoginBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                UserMobile m = new UserMobile();
                m.UserName = EmailAddress.Text;
                m.Password = Password.Text;
                progressIndicator.IsVisible = true;
                Task.Run(new Action(() =>
                    {
                        try
                        {
                            var user = UserMobileWP.Login(m);
                            if (user.IsLoggedIn)
                            {
                                user.LastMobileLoginDate = DateTime.UtcNow;
                                SqlFactory fact = new SqlFactory();
                                fact.DeleteProfile();
                                fact.InsertProfile(new SqlAccount(user));
                                var json = fact.GetNotificationSettings();
                                if (json != null)
                                {
                                    json.MemberId = user.MemberId.ToString();
                                    NotificationMobileJsonWP.SendNotificationId(json);
                                }
                                Dispatcher.BeginInvoke(delegate
                                {
                                    progressIndicator.IsVisible = false;
                                    NavigationService.Navigate(new Uri("/View/MyLeague/MyLeague.xaml", UriKind.Relative));

                                });
                            }
                            else
                            {
                                Dispatcher.BeginInvoke(delegate
                                {
                                    progressIndicator.IsVisible = false;
                                    warning.Text = "There was an error logging in, Please try again.";
                                });

                            }
                        }
                        catch (Exception exception)
                        {
                            ErrorHandler.Save(exception, MobileTypeEnum.WP8);
                        }
                        Dispatcher.BeginInvoke(delegate
                        {
                            progressIndicator.IsVisible = false;

                        });
                    }));
            }
            catch (Exception exception)
            {
                ErrorHandler.Save(exception, MobileTypeEnum.WP8);
            }
        }
Пример #2
0
        private void RegisterBtn_Click_1(object sender, RoutedEventArgs e)
        {
            try
            {
                UserMobile m = new UserMobile();

                m.UserName = Email.Text;
                m.Password = Password.Text;
                m.FirstName = FirstName.Text;
                if (GenderSelect != null && GenderSelect.SelectedItem != null)
                    m.Gender = Convert.ToInt32((GenderEnum)Enum.Parse(typeof(GenderEnum), GenderSelect.SelectedItem.ToString().Replace(" ", "_")));

                if (PositionSelect != null && PositionSelect.SelectedItem != null)
                    m.Position = Convert.ToInt32((DefaultPositionEnum)Enum.Parse(typeof(DefaultPositionEnum), PositionSelect.SelectedItem.ToString().Replace(" ", "_")));

                m.IsConnectedToDerby = YesRadio.IsChecked.GetValueOrDefault();
                RegisterBtn.IsEnabled = false;

                progressIndicator.IsVisible = true;
                Task.Run(new Action(() =>
                    {
                        try
                        {
                            var user = UserMobileWP.SignUp(m);
                            if (user.DidSignUp)
                            {
                                SqlFactory fact = new SqlFactory();
                                fact.InsertProfile(new SqlAccount(user));
                                var json = fact.GetNotificationSettings();
                                json.MemberId = user.MemberId.ToString();
                                NotificationMobileJsonWP.SendNotificationId(json);
                                Dispatcher.BeginInvoke(delegate
                                {
                                    progressIndicator.IsVisible = false;
                                    NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
                                });
                            }
                            else
                            {
                                Dispatcher.BeginInvoke(delegate
                                {
                                    progressIndicator.IsVisible = false;
                                    warning.Text = user.Error;
                                    RegisterBtn.IsEnabled = true;
                                });
                            }
                        }
                        catch (Exception exception)
                        {
                            ErrorHandler.Save(exception, MobileTypeEnum.WP8);
                        }
                        Dispatcher.BeginInvoke(delegate
                        {
                            progressIndicator.IsVisible = false;
                            RegisterBtn.IsEnabled = true;

                        });
                    }));
            }
            catch (Exception exception)
            {
                ErrorHandler.Save(exception, MobileTypeEnum.WP8);
            }
        }