Пример #1
0
        public async Task <string> AddCashBackAsync(CreditCardActions creditCardActions)
        {
            logger.LogDebug($"Within {nameof(AddCashBackAsync)} method.");
            logger.LogDebug($"Check the Card Details first.");

            CreditCard creditCard = await creditCardService.GetCreditCardInfoAsync(creditCardActions.CardHolderName);

            if (creditCard == null)
            {
                ErrorMessages.Add($"{creditCardActions.CardHolderName}:No Credit Card Exists for {creditCardActions.CardHolderName}");
                return($"No Credit Card Exists for {creditCardActions.CardHolderName}");
            }

            decimal currentBalance = creditCard.Balance;

            if (currentBalance != 0)
            {
                creditCard.Balance -= creditCardActions.Amount;
            }
            else
            {
                ErrorMessages.Add($"{creditCardActions.CardHolderName} : Cannot add Credits without Any Charges on this Card {creditCard.CardNumber} with Balance {creditCard.Balance}");
                return($"{creditCardActions.CardHolderName} : Cannot add Credits without Any Charges on this Card {creditCard.CardNumber} with Balance {creditCard.Balance}");
            }

            string response = await creditCardService.ChargeCreditCardAsync(creditCard);

            if (response == "success")
            {
                logger.LogInformation($"Credit Card Added Successfully");
                return($"{creditCard.CardHolderName}:${creditCard.Balance}");
            }
            else
            {
                return($"{creditCard.CardHolderName}:Something went wrong while Charging the CreditCard {creditCard.CardNumber} with Amount {creditCardActions.Amount}");
            }
        }