Beispiel #1
0
        private bool SaveAccountDetails()
        {
            if (string.IsNullOrEmpty(UsernameBox.Text.Trim()) ||
                string.IsNullOrEmpty(NameBox.Text.Trim()) || string.IsNullOrEmpty(SurnameBox.Text.Trim()) ||
                string.IsNullOrEmpty(StreetBox.Text.Trim()) || string.IsNullOrEmpty(ZipCodeBox.Text.Trim()) ||
                string.IsNullOrEmpty(EmailBox.Text.Trim()) || string.IsNullOrEmpty(CountryBox.Text.Trim()) ||
                string.IsNullOrEmpty(CityBox.Text.Trim()) || BirthDatePicker.SelectedDate == null)
            {
                NotificationLabel.ShowError("All account information fields required!");
                return(false);
            }
            else
            {
                UserDAO        userDAO        = new UserDAO();
                UserDetailsDAO userDetailsDAO = new UserDetailsDAO();

                User user = UserManager.CurrentUser;
                user.Username = UsernameBox.Text;
                user.Name     = NameBox.Text;
                user.Surname  = SurnameBox.Text;

                DebugLog.WriteLine(userDAO == null);

                try
                {
                    UserDetails userDetails = user.UserDetails == null ?
                                              user.UserDetails : new UserDetailsDAO().GetUserDetails(userId: user.Id).First();

                    userDetails.City      = CityBox.Text;
                    userDetails.Country   = CountryBox.Text;
                    userDetails.Email     = EmailBox.Text;
                    userDetails.Street    = StreetBox.Text;
                    userDetails.ZipCode   = ZipCodeBox.Text;
                    userDetails.BirthDate = BirthDatePicker.SelectedDate.Value;

                    userDAO.Update(user);

                    userDetailsDAO.Update(userDetails);

                    UserLabel.Content = "Welcome User " + UserManager.CurrentUser.Name + " "
                                        + UserManager.CurrentUser.Surname;

                    return(true);
                }
                catch (Exception ex)
                {
                    DebugLog.WriteLine(ex);
                    NotificationLabel.ShowError("A problem occured while trying to save settings!");
                    return(false);
                }
            }
        }
        private void SaveSettings_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(UsernameBox.Text.Trim()) ||
                string.IsNullOrEmpty(NameBox.Text.Trim()) || string.IsNullOrEmpty(SurnameBox.Text.Trim()) ||
                string.IsNullOrEmpty(StreetBox.Text.Trim()) || string.IsNullOrEmpty(ZipCodeBox.Text.Trim()) ||
                string.IsNullOrEmpty(EmailBox.Text.Trim()) || string.IsNullOrEmpty(CountryBox.Text.Trim()) ||
                string.IsNullOrEmpty(CityBox.Text.Trim()) || BirthDatePicker.SelectedDate == null)
            {
                NotificationLabel.ShowError("All account information fields required!");
            }
            else
            {
                UserDAO        userDAO        = new UserDAO();
                UserDetailsDAO userDetailsDAO = new UserDetailsDAO();

                User user = UserManager.CurrentUser;
                user.Username = UsernameBox.Text;
                user.Name     = NameBox.Text;
                user.Surname  = SurnameBox.Text;

                try
                {
                    UserDetails userDetails = user.UserDetails == null ?
                                              user.UserDetails : new UserDetailsDAO().GetUserDetails(userId: user.Id).First();

                    userDetails.City      = CityBox.Text;
                    userDetails.Country   = CountryBox.Text;
                    userDetails.Email     = EmailBox.Text;
                    userDetails.Street    = StreetBox.Text;
                    userDetails.ZipCode   = ZipCodeBox.Text;
                    userDetails.BirthDate = BirthDatePicker.SelectedDate.Value;

                    userDAO.Update(user);

                    userDetailsDAO.Update(userDetails);

                    NotificationLabel.ShowSuccess("Account Information has been updated !");
                }
                catch (Exception ex)
                {
                    DebugLog.WriteLine(ex);
                    NotificationLabel.ShowError("A problem occured while trying to save settings!");
                }
            }
        }