/// <summary>
        /// Map credit card of commerce core to credit card view model
        /// </summary>
        /// <param name="creditCard">Source credit card</param>
        /// <param name="creditCardModel">Target credit card</param>
        public void MapToModel(Mediachase.Commerce.Customers.CreditCard creditCard, ref CreditCardModel creditCardModel)
        {
            creditCardModel.CreditCardType         = (Mediachase.Commerce.Customers.CreditCard.eCreditCardType)creditCard.CardType;
            creditCardModel.CreditCardNumber       = creditCard.CreditCardNumber;
            creditCardModel.CreditCardSecurityCode = creditCard.SecurityCode;
            creditCardModel.ExpirationMonth        = creditCard.ExpirationMonth;
            creditCardModel.ExpirationYear         = creditCard.ExpirationYear;
            creditCardModel.CreditCardId           = creditCard.PrimaryKeyId.ToString();

            if (creditCard.OrganizationId != null)
            {
                creditCardModel.Organization = _organizationService.GetOrganizationModel((Guid)creditCard.OrganizationId);
            }
            else if (creditCard.ContactId != null)
            {
                creditCardModel.CurrentContact = _customerContext.GetContactById(new Guid(creditCard.ContactId.ToString()));
            }
        }
        /// <summary>
        /// Check credit card of organization is valid for edit/delete
        /// </summary>
        /// <param name="creditCard"></param>
        private bool IsValidOrganizationCard(Mediachase.Commerce.Customers.CreditCard creditCard, OrganizationModel organization)
        {
            if (creditCard.OrganizationId == organization.OrganizationId)
            {
                return(true);
            }
            else
            {
                var isValid = false;

                foreach (var subOrganization in organization.SubOrganizations)
                {
                    if (IsValidOrganizationCard(creditCard, subOrganization))
                    {
                        isValid = true;
                        break;
                    }
                }

                return(isValid);
            }
        }
        /// <summary>
        /// Map credit card view model to credit card of commerce core
        /// </summary>
        /// <param name="creditCardModel">Source credit card</param>
        /// <param name="creditCard">Target credit card</param>
        public void MapToCreditCard(CreditCardModel creditCardModel, ref Mediachase.Commerce.Customers.CreditCard creditCard)
        {
            creditCard.CardType         = (int)creditCardModel.CreditCardType;
            creditCard.CreditCardNumber = creditCardModel.CreditCardNumber;
            creditCard.LastFourDigits   =
                creditCardModel.CreditCardNumber.Substring(creditCardModel.CreditCardNumber.Length - 4);
            creditCard.SecurityCode    = creditCardModel.CreditCardSecurityCode;
            creditCard.ExpirationMonth = creditCardModel.ExpirationMonth;
            creditCard.ExpirationYear  = creditCardModel.ExpirationYear;
            if (creditCardModel.CurrentContact != null)
            {
                creditCard.ContactId = creditCardModel.CurrentContact.PrimaryKeyId;
            }
            else if (!string.IsNullOrEmpty(creditCardModel.OrganizationId))
            {
                creditCard.OrganizationId =
                    PrimaryKeyId.Parse(creditCardModel.OrganizationId);
            }

            if (!string.IsNullOrEmpty(creditCardModel.CreditCardId))
            {
                creditCard.PrimaryKeyId = PrimaryKeyId.Parse(creditCardModel.CreditCardId);
            }
        }