Esempio n. 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;
        }
        async Task CreateAndShowPersonFromInputedData(object o)
        {
            Console.WriteLine(DateOfBirth);
            if (BirthDataUtils.IsValidBirthDate(DateOfBirth) == false)
            {
                MessageBox.Show("Invalid date", "error", MessageBoxButton.OKCancel, MessageBoxImage.Error);
                return;
            }
            if (BirthDataUtils.IsBirthday(DateOfBirth))
            {
                MessageBox.Show("Happy Birth Day To You!", "Don't worry be happy)",
                                MessageBoxButton.OK, MessageBoxImage.Asterisk);
            }

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


            var person       = new Person(Name, Surname, Email, DateOfBirth);
            var personInfoVM = new PersonInfoViewModel(person);

            _personInfoGrid.DataContext = personInfoVM;

            _personInfoGrid.Visibility = Visibility.Visible;
        }
Esempio n. 3
0
 internal Person(string name, string surname, string email) : this(name, surname)
 {
     if (email == null)
     {
         throw new ArgumentNullException(nameof(email));
     }
     if (!EmailValidator.IsValidFormat(email))
     {
         throw new ArgumentException("the email is badly fomatted");
     }
     Email = email;
 }