コード例 #1
0
        public async Task <string> AddCreditCardAsync(AddCreditCard addCreditCardModel)
        {
            logger.LogDebug($"Within {nameof(AddCreditCardAsync)} method.");
            var ValidLimit = this.validationBuilder.ValidateCardLimit(addCreditCardModel.CreditLimit, out string errorMessage);

            if (!ValidLimit)
            {
                ErrorMessages.Add($"{addCreditCardModel.CardHolderName}:{errorMessage}");
                return($"{addCreditCardModel.CardHolderName}:{errorMessage}");
            }

            var ValidateCardHolderName = this.validationBuilder.ValidateCardName(addCreditCardModel.CardHolderName, out string InValidCardHolderError);

            if (!ValidateCardHolderName)
            {
                ErrorMessages.Add($"{addCreditCardModel.CardHolderName}:{InValidCardHolderError}");
                return($"{addCreditCardModel.CardHolderName}:{InValidCardHolderError}");
            }

            var ValidateCardNumber = this.validationBuilder.ValidateCardNumber(addCreditCardModel.CardNumber, out string InValidCardNumberError);

            if (!ValidateCardNumber)
            {
                ErrorMessages.Add($"{addCreditCardModel.CardHolderName}:{InValidCardNumberError}");
                return($"{addCreditCardModel.CardHolderName}:{InValidCardNumberError}");
            }

            logger.LogDebug($"Validation is Successfull");
            CreditCard dbObject = mapper.Map <CreditCard>(addCreditCardModel);

            dbObject.TotalCreditLimit = addCreditCardModel.CreditLimit;

            logger.LogInformation($"Created DbObject for Creating a new CreditCard");
            logger.LogInformation($"All Validations were Succeeded");

            string response = await creditCardService.AddCreditCardAsync(dbObject);

            if (response == "success")
            {
                logger.LogInformation($"Credit Card Added Successfully");
                return($"{dbObject.CardHolderName}:${dbObject.Balance}");
            }
            return($"{addCreditCardModel.CardHolderName}:An Error occured while processing the request");
        }