Example #1
0
        async Task CreateAndShowPersonFromInputedData(object o)
        {
            Console.WriteLine(DateOfBirth);
            if (DateOfBirthday.DateOfBirthIsTrue(DateOfBirth) == false)
            {
                MessageBox.Show("Enter a valid date!", "error", MessageBoxButton.OKCancel, MessageBoxImage.Error);
                return;
            }
            if (DateOfBirthday.IsBirthday(DateOfBirth))
            {
                MessageBox.Show("Wow, it's your birthday! Go enjoy yourself.", "your only invite today",
                                MessageBoxButton.OK, MessageBoxImage.Asterisk);
            }

            if (!EmailValidator.IsValidFormat(Email))
            {
                MessageBox.Show("The email is badly formatted!", "error", MessageBoxButton.OKCancel, MessageBoxImage.Error);
                return;
            }

            // cannot access DataContext from non-ui thread
            // and anyway, creating the new thread would take more time that just execution this code
            var person       = new Person(Name, Surname, Email, DateOfBirth);
            var personInfoVM = new PersonInfoViewModel(person);

            _personInfoGrid.DataContext = personInfoVM;

            _personInfoGrid.Visibility = Visibility.Visible;
        }
 internal MainWindowViewModel(PersonInfoViewModel personInfoVm)
 {
     _personInfoVm           = personInfoVm ?? throw new ArgumentNullException(nameof(personInfoVm));
     PersonDataSubmitCommand = new DelegateCommandAsync(CreateAndShowPersonFromInputedData, AllFieldsHaveBeenSet);
 }