예제 #1
0
        /// <summary>
        /// Attempts to register a new user and organisation with the service
        /// using form data.
        /// </summary>
        private void Register()
        {
            IsLoadingVisible        = true;
            IsRegisterButtonEnabled = false;

            if (CanRegister())
            {
                Task openConnection = new Task(() =>
                {
                    try
                    {
                        User user = new User
                        {
                            FirstName = this.FirstName,
                            Surname   = this.LastName,
                            Password  = this.Password,
                            Username  = this.Email,
                        };

                        // Execute registration operation concurrently
                        _Service.Register(user);
                    }
                    catch (FaultException e)
                    {
                        IsRegisterButtonEnabled = true;
                        IsLoadingVisible        = false;

                        MessageBox.Show(e.Message);
                    }
                });

                Task openWindow = openConnection.ContinueWith(p =>
                {
                    if (p.Exception == null)
                    {
                        RegistrationSuccessPanel  = _ControlFactory.CreateRegistrationSuccessPanel(_Email, this);
                        IsRegistrationFormVisible = false;
                    }
                    else
                    {
                        IsLoadingVisible        = false;
                        IsRegisterButtonEnabled = true;
                    }
                }, TaskScheduler.FromCurrentSynchronizationContext());

                openConnection.Start();
            }
            else
            {
                IsLoadingVisible        = false;
                IsRegisterButtonEnabled = true;
            }
        }