public ActionResult OpenAccount(OpenAccountViewModel viewModel) { if (ModelState.IsValid) { using (CryptoWalletDbContext ctx = new CryptoWalletDbContext()) { User currentUser = ctx.Users.AsNoTracking().FirstOrDefault(u => u.Email == User.Identity.Name); List <UserBankAccount> currentUserAccounts = ctx.UserBankAccounts.Where(b => b.UserId == currentUser.UserId).ToList(); UserBankAccount bankAccount = currentUserAccounts.FirstOrDefault(x => x.Currency == viewModel.NewCurrency); if (bankAccount != null) { ModelState.AddModelError("", "You have already an account in this currency."); SetupOpenAccount(viewModel); return(View(viewModel)); } bankAccount = new UserBankAccount { Currency = viewModel.NewCurrency, UserId = currentUser.UserId }; // bankAccount.User = currentUser; ----- imi aduce userid gresit bankAccount.UserId = currentUser.UserId; ctx.UserBankAccounts.Add(bankAccount); ctx.SaveChanges(); return(RedirectToAction("Index")); } } else { SetupOpenAccount(viewModel); return(View(viewModel)); } }
public async Task OpenAccount_Given_CustomerAlreadyHasCpfRegistered_Then_ReturnConflictObjectResult() { var mockCustomerService = new Mock <ICustomerAppService>(); var mockAuthSettings = new Mock <IOptions <AuthSettings> >(); var customer = new Customer("jak1i2k3i-k12i3k-12ki3k1", "1645545852", "Teste", DateTime.Now); var openAccountViewModel = new OpenAccountViewModel() { Agency = 3032, Customer = new CustomerViewModel() { BirthDate = customer.BirthDate, Cpf = customer.Cpf, Name = customer.Name }, Email = "*****@*****.**", Password = "******" }; mockCustomerService.Setup(c => c.GetByCpf(It.IsAny <string>())).ReturnsAsync(customer); // Arrange var controller = new AuthController(customerAppService: mockCustomerService.Object, AuthSettings: mockAuthSettings.Object); //Act var result = await controller.OpenAccount(openAccountViewModel); // Assert Assert.IsType <ConflictObjectResult>(result); }
public ActionResult OpenAccount() { OpenAccountViewModel viewModel = new OpenAccountViewModel(); SetupOpenAccount(viewModel); return(View(viewModel)); }
public async Task <Account> RegisterAsync(OpenAccountViewModel openAccount) { // cria cliente na memória var customer = _mapper.Map <Customer>(openAccount.Customer); customer.CustomerId = Guid.NewGuid().ToString(); // busca usuário criado para vincular a conta var user = await _userManager.FindByEmailAsync(openAccount.Email); // cria conta var account = new Account(Guid.NewGuid().ToString(), openAccount.Agency, customer.CustomerId); if (await _accountRepository.GetByAccountNumberAsync(account.AccountNumber) != null) { throw new InvalidOperationException("Já existe uma conta com este número"); } account.UserId = user.Id; account.Customer = customer; // salva a conta e o cliente juntos com o ef core await _accountRepository.AddAsync(account); return(account); }
private void SetupOpenAccount(OpenAccountViewModel viewModel) { using (CryptoWalletDbContext ctx = new CryptoWalletDbContext()) { viewModel.UnopenedAccounts = Enum.GetValues(typeof(Currency)).Cast <Currency>().Select(v => new SelectListItem { Text = v.ToString(), Value = v.ToString() }).ToList(); } }
public async Task <ActionResult> OpenAccount(OpenAccountViewModel account) { if (!ModelState.IsValid) { return(View()); } await Task.Run(() => _accountService.OpenAccount(account.Type, account.OwnerFirstName, account.OwnerSecondName, account.Sum, User.Identity.Name, _accountIdService)); TempData["isAccountOpened"] = true; return(RedirectToAction(nameof(this.AccountSuccessfullyOpened))); }
public async Task <ActionResult> OpenAccount(OpenAccountViewModel openAccount) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values.SelectMany(e => e.Errors))); } var identityUser = new IdentityUser { UserName = openAccount.Email, Email = openAccount.Email, EmailConfirmed = true }; if (await _customerAppService.GetByCpf(openAccount.Customer.Cpf) != null) { return(Conflict("Já existe um cliente com o cpf informado")); } if (await _userManager.FindByEmailAsync(openAccount.Email) != null) { return(Conflict("Já existe um cliente com o e-mail informado")); } var result = await _userManager.CreateAsync(identityUser, openAccount.Password); if (!result.Succeeded) { return(BadRequest(result.Errors.Select(i => i.Description))); } var account = await _accountAppService.RegisterAsync(openAccount); return(Ok(new { account.Agency, account.AccountNumber, message = "Conta aberta com sucesso" })); } catch (InvalidOperationException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { return(BadRequest($"Erro ao abrir conta. {ex.Message}")); } }
public ActionResult OpenAccount(OpenAccountViewModel viewModel) { if (!ModelState.IsValid) { return(this.View()); } string userEmail = User.Identity.Name; var accountNumber = _bankManageService.CreateAccount(userEmail, viewModel.Password, viewModel.Type, viewModel.Balance); if (_bankManageService.GetAccountInfo(userEmail, accountNumber) is null) { return(this.RedirectToAction("OpenAccount")); } return(this.View("AccountIsOpened")); }
public JsonResult OpenAccount(OpenAccountViewModel model) { return(BizFactory.Merchant.OpenAccount(this.CurrentUserId, model.Merchant, model.MerchantPosMachine, model.BankCard)); }