Example #1
0
        private async void CreatePersonImpl(object o)
        {
            Person newPerson = null;

            CurrentPerson.CurrUser = null;
            _showLoaderAction.Invoke(true);
            await Task.Run(() =>
            {
                try
                {
                    newPerson = new Person(_firstName, _lastName, _email, _dateOfBirth);
                    Thread.Sleep(2000);

                    CurrentPerson.CurrUser = newPerson;
                    if (CurrentPerson.CurrUser.IsBirthday)
                    {
                        MessageBox.Show("Happy birhday, buddy! Now you're closer to your death than year ago)");
                    }

                    MessageBox.Show("Person was added successfully" + Environment.NewLine + CurrentPerson.CurrUser.ToString());
                    DBAdapter.AddPerson(newPerson);
                }

                catch (InvalidNameException e)
                {
                    MessageBox.Show(e.Message);
                }
                catch (InvalidEmailException e)
                {
                    MessageBox.Show(e.Message);
                }
                catch (NegativeAgeException e)
                {
                    MessageBox.Show(e.Message);
                }
                catch (DiedPersonException e)
                {
                    MessageBox.Show(e.Message);
                }
            });

            _showLoaderAction.Invoke(false);

            if (CurrentPerson.CurrUser != null)
            {
                _closeAction.Invoke();
            }
            _updatePeopleView.Invoke();
        }