示例#1
0
        public ActionResult CreateCreditCard()
        {
            CardViewModel cardViewModel = new CardViewModel();
            cardViewModel.CardTypes = new List<SelectListItem>
            {
                new SelectListItem() {Text="Credit", Value="Credit"},
                new SelectListItem() {Text="Debit", Value="Debit"}
            };

            return View(cardViewModel);
        }
示例#2
0
        private CardViewModel GetCardViewModel()
        {
            CardViewModel cardViewModel = new CardViewModel();
            cardViewModel.CardTypes = new List<SelectListItem>
            {
                new SelectListItem() {Text="Credit", Value="Credit"},
                new SelectListItem() {Text="Debit", Value="Debit"}
            };

            string userId = User.Identity.GetUserId();
            Customer customer = _customerRepository.GetCustomerByUserId(userId);
            IEnumerable<Account> accounts = _accountRepository.GetAllAccountsByCustomerId(customer.Id);
            cardViewModel.Accounts = accounts.Select(c => new SelectListItem { Text = c.AccountNumber, Value = c.Id.ToString() });

            return cardViewModel;
        }
示例#3
0
        public JsonResult CreateCreditCard(CardViewModel cardViewModel)
        {
            if (!ModelState.IsValid)
            {
                cardViewModel.CardTypes = new List<SelectListItem>
                {
                    new SelectListItem() {Text="Credit", Value="Credit"},
                    new SelectListItem() {Text="Debit", Value="Debit"}
                };
                
                return Json(new { Result = "Error. Please, check the input data."});
            }
            
            int balanceIdForAccount = _accountRepository.GetAccountById(cardViewModel.AccountId).BalanceId;
            Balance balanceForAccount = _balanceRepository.GetBalanceById(balanceIdForAccount);

            Balance balance = new Balance
            {
                CurrencyId = balanceForAccount.CurrencyId,
                AvialableFunds = 0
            };

            int balanceId = _balanceRepository.Add(balance);

            Card card = new Card
            {
                Number = CreateCardNumber(20),
                Type = cardViewModel.Type,
                CardholderName = cardViewModel.CardholderName,
                SecurityNumber = CreateCardNumber(7),
                BalanceId = balanceId,
                ExpireDate = DateTime.Now.AddYears(4),
                AccountId = cardViewModel.AccountId
            };
            _cardRepository.Add(card);

            return Json(new { Result = "Success"});
        }