Exemple #1
0
        public ActionResult Save(PaymentCardFormViewModel paymentCardViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("PaymentCardForm", paymentCardViewModel));
            }
            //check if it's a new payment card
            if (paymentCardViewModel.PaymentCard.Id == 0)
            {
                var paymentCard = paymentCardViewModel.PaymentCard;
                _context.PaymentCards.Add(paymentCard);
                _context.SaveChanges();
            }
            else
            {
                var paymentCardInDb = _context.PaymentCards.Find(paymentCardViewModel.PaymentCard.Id);
                if (paymentCardInDb == null)
                {
                    return(HttpNotFound());
                }
                paymentCardInDb.Code       = paymentCardViewModel.PaymentCard.Code;
                paymentCardInDb.Name       = paymentCardViewModel.PaymentCard.Name;
                paymentCardInDb.CardTypeId = paymentCardViewModel.PaymentCard.CardTypeId;

                _context.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Exemple #2
0
        //create new payment card
        public ActionResult New()
        {
            var paymentCard = new PaymentCard
            {
                Id = 0
            };

            var paymentCardViewModel = new PaymentCardFormViewModel
            {
                ActionIndicator = 1,
                PaymentCard     = paymentCard,
                CardTypes       = _context.CardTypes.ToList()
            };

            return(View("PaymentCardForm", paymentCardViewModel));
        }
Exemple #3
0
        public ActionResult Edit(int id)
        {
            var paymentCardInDb = _context.PaymentCards.Find(id);

            if (paymentCardInDb == null)
            {
                return(HttpNotFound());
            }
            var paymentCardViewModel = new PaymentCardFormViewModel
            {
                ActionIndicator = 2,
                PaymentCard     = paymentCardInDb,
                CardTypes       = _context.CardTypes.ToList()
            };

            return(View("PaymentCardForm", paymentCardViewModel));
        }