Beispiel #1
0
        public async Task <IActionResult> Signup([Bind("Id, Password, Repassword, Name, Phone, Email, Address")] CreateAccountView model)
        {
            if (ModelState.IsValid)
            {
                if (model.Password != model.Repassword)
                {
                    ModelState.AddModelError("Repassword", "Mật khẩu không khớp");
                    return(View(model));
                }
                if (_context.Account.Any(key => key.Id == model.Id))
                {
                    ModelState.AddModelError("Id", "Tên tài khoản đã tồn tại");
                    return(View(model));
                }
                Account account = new Account();
                account.Id        = model.Id;
                account.Password  = model.Password;
                account.Name      = model.Name;
                account.Privilege = 2;
                account.Phone     = model.Phone;
                account.Email     = model.Email;
                account.Address   = model.Address;
                _context.Account.Add(account);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Success)));
            }
            return(View(model));
        }
Beispiel #2
0
        /// <summary>
        /// Opens a new window to create a new account
        /// </summary>
        /// <param name="viewModel">View model for the window</param>
        public void OpenCreateAccountWindow(AccountViewModel viewModel)
        {
            CreateAccountView view = new CreateAccountView()
            {
                DataContext = viewModel
            };

            view.ShowDialog();
        }
Beispiel #3
0
        public void Create_Account_Test()
        {
            var consoleMock = new Mock <IShell>();

            consoleMock.SetupSequence(c => c.ReadLine())
            .Returns("1111")
            .Returns("2000");
            var     repoMock = new Mock <IRepository>();
            var     accId    = 0;
            decimal balance  = 0;

            repoMock.Setup(r => r.Save(It.IsAny <Account>()))
            .Callback <Account>(a => (accId, balance) = (a.AccountId, a.Balance));
            var createAccView = new CreateAccountView("fool", consoleMock.Object, repoMock.Object);

            createAccView.Show();
            Assert.Equal(1111, accId);
            Assert.Equal(2000, balance);
        }
Beispiel #4
0
        public void Create_Account_Test()
        {
            var consoleMock = new Mock <IShell>();

            consoleMock.SetupSequence(c => c.ReadLine())
            .Returns("1111")
            .Returns("2000");
            var repoMock    = new Mock <IRepository>();
            var factoryMock = new Mock <IAccountFactory>();
            var accMock     = new Mock <IAccount>();

            factoryMock.Setup(f => f.CreateAccount(1111, 2000)).Returns(accMock.Object);
            repoMock.Setup(r => r.Save(accMock.Object));
            var createAccView = new CreateAccountView("fool", consoleMock.Object, repoMock.Object, factoryMock.Object);

            createAccView.Show();
            factoryMock.VerifyAll();
            repoMock.VerifyAll();
        }
 public CreateAccountViewModel(CreateAccountView window)
 {
     caller = window;
 }