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 })); }
public ActionResult Create(int id) { var creditCard = new CreditCardFormViewModel() { CustomerID = id }; return(View(creditCard)); }
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)); }