Ejemplo n.º 1
0
        public ActionResult <PaymentCardDto> CreateCard([FromBody] CardCreationDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var bankAccount = _context.BankAccounts.SingleOrDefault(b => b.Id == model.BankAccountId);

            if (bankAccount == null)
            {
                ModelState.AddModelError(nameof(model.BankAccountId),
                                         $"Bank account with id {model.BankAccountId} doesn't exist.");
                return(BadRequest(ModelState));
            }

            var visaPaymentCardNumberBuilder =
                _paymentCardNumberFactory.GetPaymentCardNumberBuilder(IssuingNetwork.Visa);
            var visaPaymentCardNumber =
                visaPaymentCardNumberBuilder.GeneratePaymentCardNumber(IssuingNetworkSettings.Visa.Length.Sixteen,
                                                                       (int)model.BankAccountId);

            var paymentCard = _mapper.Map <PaymentCard>(visaPaymentCardNumber);

            paymentCard.BankAccountId = (int)model.BankAccountId;

            _context.PaymentCards.Add(paymentCard);
            _context.SaveChanges();

            return(Ok(_mapper.Map <PaymentCardDto>(paymentCard)));
        }
Ejemplo n.º 2
0
        public RedirectToActionResult AddToShoppingCart()
        {
            var card = new CardCreationDto()
            {
                Message  = TempStorage.Message,
                Template = TempStorage.Template,
                Stamp    = TempStorage.Stamp,
                Theme    = TempStorage.Theme
            };

            if (card != null)
            {
                //maybe change number for user input
                _shoppingCart.AddCart(card, 1);
            }
            return(RedirectToAction("Index"));
        }