Example #1
0
        private void BtnAddUser_Click(object sender, RoutedEventArgs e)
        {
            // Id is required
            if (string.IsNullOrEmpty(txtName.Text))
            {
                MessageBox.Show("Please enter User Id", "Required", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            // Password is required
            if (string.IsNullOrEmpty(txtPassword.Password))
            {
                MessageBox.Show("Please enter User Password", "Required", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            User user = new User
            {
                Name     = txtName.Text,
                Password = txtPassword.Password,
                Account  = new Account
                {
                    Balance = 0,
                }
            };

            repo.AddNewUser(user);

            Close();
        }
Example #2
0
        public ActionResult Add(UserViewModel uvm)
        {
            if (uvm.NewUserDto == null)
            {
                return(Redirect("Index"));
            }

            NewUserValidator validator = new NewUserValidator();
            ValidationResult result    = validator.Validate(uvm.NewUserDto);

            if (!result.IsValid)
            {
                result.Errors.ToList().ForEach(error =>
                {
                    ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
                });

                return(View(uvm));
            }
            else if (uvm.IsExist(uvm.NewUserDto.Username))
            {
                ModelState.AddModelError("UserName", "User name has existed.");
                return(View(uvm));
            }
            else
            {
                uvm.NewUserDto.Userpwd = Common.Utility.EncryptUtils.MD5Encrypt(uvm.NewUserDto.Userpwd);
                uvm.AddNewUser(uvm.NewUserDto);
                return(Redirect("Index"));
            }
        }