Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("NickName, AccountType")] Account account)
        {
            account.AppUserId   = UserManager.GetUserId(User);
            account.DateCreated = DateTime.Now;
            if (ModelState.IsValid)
            {
                switch (account.AccountType)
                {
                case "Business":
                {
                    BusinessAccount bAcct = new BusinessAccount
                    {
                        AppUserId    = account.AppUserId,
                        DateCreated  = account.DateCreated,
                        InterestRate = Account.BusinessInterestRate,
                        NickName     = account.NickName,
                        AccountType  = account.AccountType
                    };
                    await _repo.Add(bAcct);

                    return(RedirectToAction(nameof(Index)));
                }

                case "Checking":
                {
                    CheckingAccount cAcct = new CheckingAccount
                    {
                        AppUserId    = account.AppUserId,
                        DateCreated  = account.DateCreated,
                        InterestRate = Account.CheckingInterestRate,
                        NickName     = account.NickName,
                        AccountType  = account.AccountType
                    };
                    await _repo.Add(cAcct);

                    return(RedirectToAction(nameof(Index)));
                }

                default:
                {
                    return(View(account));
                }
                }
            }
            return(View(account));
        }
        private void BtnSaveAccount_Click(object sender, RoutedEventArgs e)
        {
            AccountDto account = new AccountDto();

            account.Name = tbName.Text;

            account.IdCurrency = ((ComboItem)cbCurrency.SelectedItem).Id;

            if (Id == null)
            {
                _accountRepo.Add(account);
            }
            else
            {
                account.Id = Id.Value;
                _accountRepo.Update(account);
            }

            this.Close();
        }
Esempio n. 3
0
        public async Task <ActionResult> Edit(AccountViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                await AddCurrencies(vm);

                return(View(vm));
            }

            AccountDto dto = Mapper.Map <AccountViewModel, AccountDto>(vm);

            if (vm.Id == 0)
            {
                await _accountRepo.Add(dto);
            }
            else
            {
                await _accountRepo.Update(dto);
            }
            return(RedirectToAction("Index"));
        }