Esempio n. 1
0
        public ActionResult Create(CreditCardFormViewModel viewModel)
        {
            var userId = User.Identity.GetUserId();

            var creditCard = new CreditCard(userId, viewModel.CardNumber, viewModel.GetDateTime(), viewModel.CCV);

            _unitOfWork.CreditCards.Add(creditCard);
            _unitOfWork.Complete();

            return(View("Subscribe", creditCard));
        }
Esempio n. 2
0
        public ActionResult Create(CreditCardFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("Create", viewModel));
            }

            //if (id == null)
            //{
            //    return HttpNotFound();
            //}

            var newCreditCard = new CreditCard(viewModel.Type, viewModel.CreditCardNumber, viewModel.GetDateTime(), viewModel.CustomerID);

            //{
            //    CustomerID = id.Value,
            //    CreditCardNumber = viewModel.CreditCardNumber,
            //    Type = viewModel.Type,
            //    ExpireDate = viewModel.GetDateTime()
            //};

            try
            {
                _context.CreditCards.Add(newCreditCard);
                _context.SaveChanges();
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes");
            }

            return(RedirectToAction("CustomerProfile", "Customers", new { id = newCreditCard.CustomerID }));
        }