private void SaveBankingChanges(MerchantModel editMerchant, ApplicationDbContext ctx)
        {
            try
            {
                foreach (RepeaterItem rItem in rptrBankingChanges.Items)
                {
                    Label lblFieldName = (Label)rItem.FindControl("lblFieldName3");
                    Label lblNewValue = (Label)rItem.FindControl("lblNewValue3");
                    CheckBox cbConfirmed = (CheckBox)rItem.FindControl("cbConfirmed3");

                    if (lblFieldName != null && lblNewValue != null && cbConfirmed != null)
                    {
                        if (lblFieldName.Text == "Bank Name")
                        {
                            if (cbConfirmed.Checked)
                            {
                                AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, editMerchant.BankAccount.Bank.BankName, lblNewValue.Text);

                                editMerchant.BankAccount.Bank.BankName = lblNewValue.Text.Trim();
                            }
                            else
                            {
                                txtBankName.Text = editMerchant.BankAccount.Bank.BankName;
                            }
                        }

                        if (lblFieldName.Text == "Bank City")
                        {
                            if (cbConfirmed.Checked)
                            {
                                AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, editMerchant.BankAccount.Bank.BankCity, lblNewValue.Text);

                                editMerchant.BankAccount.Bank.BankCity = lblNewValue.Text.Trim();
                            }
                            else
                            {
                                txtBankCity.Text = editMerchant.BankAccount.Bank.BankCity;
                            }
                        }

                        if (lblFieldName.Text == "Bank Phone")
                        {
                            if (cbConfirmed.Checked)
                            {
                                AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, editMerchant.BankAccount.Bank.BankPhone, lblNewValue.Text);

                                editMerchant.BankAccount.Bank.BankPhone = lblNewValue.Text.Trim();
                            }
                            else
                            {
                                txtBankPhone.Text = editMerchant.BankAccount.Bank.BankPhone;
                            }
                        }

                        if (lblFieldName.Text == "Bank State")
                        {
                            if (cbConfirmed.Checked)
                            {
                                AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, editMerchant.BankAccount.Bank.BankState.Name, lblNewValue.Text);

                                editMerchant.BankAccount.Bank.BankState = ctx.GeoStates.First(gs => gs.Name == lblNewValue.Text);
                            }
                            else
                            {
                                ddlBankState.SelectedValue = editMerchant.BankAccount.Bank.BankState.RecordId.ToString();
                            }
                        }

                        if (lblFieldName.Text == "Debit Card")
                        {
                            if (cbConfirmed.Checked)
                            {
                                string oldDebitCard = MaskDebitCard(editMerchant.DebitCard.DebitCardNumber, editMerchant.DebitCard.RecordId);

                                Logic.Crypt crypto1 = new Logic.Crypt();
                                crypto1.CryptType = "Card";
                                crypto1.CryptData = Convert.ToBase64String(PWDTK.StringToUtf8Bytes(lblNewValue.Text));
                                crypto1.Purpose = "9c443c6a-87d5-47cc-9c4d-abf6a2bd2e06";
                                crypto1.AdditionalData = editMerchant.DebitCard.RecordId.ToString();

                                byte[] newDebitCard = crypto1.Protect();

                                editMerchant.DebitCard.DebitCardNumber = newDebitCard;
                                editMerchant.DebitCard.DebitCardFirst6 = txtDebitCardNumber.Text.Substring(0, 6);
                                editMerchant.DebitCard.DebitCardLast4 = txtDebitCardNumber.Text.Substring(txtDebitCardNumber.Text.Length - 4, 4);
                                editMerchant.DebitCard.RemainingDigits = Convert.ToInt16(txtDebitCardNumber.Text.Length - 10);

                                AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, oldDebitCard, MaskDebitCard(newDebitCard, editMerchant.DebitCard.RecordId));
                            }
                            else
                            {
                                txtDebitCardNumber.Text = MaskDebitCard(editMerchant.DebitCard.DebitCardNumber, editMerchant.DebitCard.RecordId);
                            }

                            txtDebitCardNumber.Enabled = false;
                        }

                        if (lblFieldName.Text == "Account Number")
                        {
                            if (cbConfirmed.Checked)
                            {
                                string oldAccNum = MaskAccountNumber(editMerchant.BankAccount.AccountNumber, editMerchant.BankAccount.RecordId);

                                Logic.Crypt crypto2 = new Logic.Crypt();
                                crypto2.CryptType = "Account";
                                crypto2.CryptData = Convert.ToBase64String(PWDTK.StringToUtf8Bytes(lblNewValue.Text.Trim()));
                                crypto2.Purpose = "4742b06b-9e12-48cf-9034-aadb15dc7a58";
                                crypto2.AdditionalData = editMerchant.BankAccount.RecordId.ToString();

                                byte[] newAccNum = crypto2.Protect();

                                editMerchant.BankAccount.AccountNumber = newAccNum;
                                editMerchant.BankAccount.AccountNumberLast4 = txtAccountNumber.Text.Substring(txtAccountNumber.Text.Length - 4, 4);
                                editMerchant.BankAccount.RemainingDigits = Convert.ToInt16(txtAccountNumber.Text.Length - 4);

                                AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, oldAccNum, MaskAccountNumber(newAccNum, editMerchant.BankAccount.RecordId));
                            }
                            else
                            {
                                txtAccountNumber.Text = MaskAccountNumber(editMerchant.BankAccount.AccountNumber, editMerchant.BankAccount.RecordId);
                            }

                            txtAccountNumber.Enabled = false;
                        }

                        if (lblFieldName.Text == "Exp Month")
                        {
                            if (cbConfirmed.Checked)
                            {
                                AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, editMerchant.DebitCard.DebitCardExpMonth, lblNewValue.Text);

                                editMerchant.DebitCard.DebitCardExpMonth = lblNewValue.Text;
                            }
                            else
                            {
                                ddlExpMonth.SelectedValue = editMerchant.DebitCard.DebitCardExpMonth.ToString();
                            }

                            ddlExpMonth.Enabled = false;
                        }

                        if (lblFieldName.Text == "Exp Year")
                        {
                            if (cbConfirmed.Checked)
                            {
                                AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, editMerchant.DebitCard.DebitCardExpYear, lblNewValue.Text);

                                editMerchant.DebitCard.DebitCardExpYear = lblNewValue.Text;
                            }
                            else
                            {
                                ddlExpYear.SelectedValue = editMerchant.DebitCard.DebitCardExpYear.ToString();
                            }

                            ddlExpYear.Enabled = false;
                        }

                        if (lblFieldName.Text == "Routing Number")
                        {
                            if (cbConfirmed.Checked)
                            {
                                AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, editMerchant.BankAccount.RoutingNumber, lblNewValue.Text);

                                editMerchant.BankAccount.RoutingNumber = lblNewValue.Text.Trim();
                            }
                            else
                            {
                                txtRoutingNumber.Text = editMerchant.BankAccount.RoutingNumber;
                            }

                            txtRoutingNumber.Enabled = false;
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                string userId = "";

                if (Request.IsAuthenticated)
                {
                    userId = Page.User.Identity.GetUserId();
                }
                _newLogic.WriteExceptionToDB(ex, "SaveBankingChanges", 0, editMerchant.RecordId, userId);
            }
        }
        private void SavePrincipalChanges(MerchantModel editMerchant, ApplicationDbContext ctx)
        {
            try
            {
                foreach (RepeaterItem rItem in rptrPrincipalChanges.Items)
                {
                    Label lblFieldName = (Label)rItem.FindControl("lblFieldName1");
                    Label lblNewValue = (Label)rItem.FindControl("lblNewValue1");
                    CheckBox cbConfirmed = (CheckBox)rItem.FindControl("cbConfirmed1");

                    if (lblFieldName != null && lblNewValue != null && cbConfirmed != null)
                    {
                        if (lblFieldName.Text == "First Name")
                        {
                            if (cbConfirmed.Checked)
                            {
                                AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, editMerchant.MerchantPrincipal.Contact.FirstName, lblNewValue.Text);

                                editMerchant.MerchantPrincipal.Contact.FirstName = lblNewValue.Text;
                            }
                            else
                            {
                                txtPrincipalFirstName.Text = editMerchant.MerchantPrincipal.Contact.FirstName;
                            }
                        }

                        if (lblFieldName.Text == "Last Name")
                        {
                            if (cbConfirmed.Checked)
                            {
                                AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, editMerchant.MerchantPrincipal.Contact.LastName, lblNewValue.Text);

                                editMerchant.MerchantPrincipal.Contact.LastName = lblNewValue.Text;
                            }
                            else
                            {
                                txtPrincipalLastName.Text = editMerchant.MerchantPrincipal.Contact.LastName;
                            }
                        }

                        if (lblFieldName.Text == "M.I.")
                        {
                            if (cbConfirmed.Checked)
                            {
                                AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, editMerchant.MerchantPrincipal.Contact.MiddleInitial, lblNewValue.Text);

                                editMerchant.MerchantPrincipal.Contact.MiddleInitial = lblNewValue.Text;
                            }
                            else
                            {
                                txtPrincipalMI.Text = editMerchant.MerchantPrincipal.Contact.MiddleInitial;
                            }
                        }

                        if (lblFieldName.Text == "D.O.B.")
                        {
                            if (cbConfirmed.Checked)
                            {
                                AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, editMerchant.MerchantPrincipal.PrincipalDoB.ToString(), lblNewValue.Text);

                                editMerchant.MerchantPrincipal.PrincipalDoB = Convert.ToDateTime(lblNewValue.Text);
                            }
                            else
                            {
                                if (editMerchant.MerchantPrincipal.PrincipalDoB.HasValue)
                                {
                                    ddlBirthYear.SelectedValue = editMerchant.MerchantPrincipal.PrincipalDoB.Value.Year.ToString();
                                    ddlBirthMonth.SelectedValue = editMerchant.MerchantPrincipal.PrincipalDoB.Value.Month.ToString();
                                    ddlBirthDay.SelectedValue = editMerchant.MerchantPrincipal.PrincipalDoB.Value.Day.ToString();
                                }
                                else
                                {
                                    ddlBirthYear.SelectedIndex = -1;
                                    ddlBirthMonth.SelectedIndex = -1;
                                    ddlBirthDay.SelectedIndex = -1;
                                }
                            }
                        }

                        if (lblFieldName.Text == "S.S.N.")
                        {
                            if (cbConfirmed.Checked)
                            {
                                String maskedOldSsn = MaskSsn(editMerchant.MerchantPrincipal.PrincipalSsn, editMerchant.MerchantPrincipal.RecordId);

                                Logic.Crypt crypto1 = new Logic.Crypt();
                                crypto1.CryptType = "SSN";
                                crypto1.CryptData = Convert.ToBase64String(PWDTK.StringToUtf8Bytes(lblNewValue.Text));
                                crypto1.Purpose = "86d4b5b2-b34a-4968-9fde-f8ed677bca8b";
                                crypto1.AdditionalData = editMerchant.MerchantPrincipal.RecordId.ToString();

                                byte[] newSsn = crypto1.Protect();

                                editMerchant.MerchantPrincipal.PrincipalSsn = newSsn;

                                AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, maskedOldSsn, MaskSsn(newSsn, editMerchant.MerchantPrincipal.RecordId));

                            }
                            else
                            {
                                if (editMerchant.MerchantPrincipal.PrincipalSsn != null)
                                {
                                    txtPrincipalSSN.Text = MaskSsn(editMerchant.MerchantPrincipal.PrincipalSsn, editMerchant.MerchantPrincipal.RecordId);
                                }
                                else
                                {
                                    txtPrincipalSSN.Text = "";
                                }
                            }

                            txtPrincipalSSN.Enabled = false;
                        }

                        if (lblFieldName.Text == "% Ownership")
                        {
                            if (cbConfirmed.Checked)
                            {
                                AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, editMerchant.MerchantPrincipal.PrincipalPctOwn.ToString(), lblNewValue.Text);

                                editMerchant.MerchantPrincipal.PrincipalPctOwn = Convert.ToDecimal(lblNewValue.Text.Substring(0, lblNewValue.Text.Length - 2));
                            }
                            else
                            {
                                if (editMerchant.MerchantPrincipal.PrincipalPctOwn.HasValue)
                                {
                                    txtPrincipalPctOwn.Text = editMerchant.MerchantPrincipal.PrincipalPctOwn.ToString();
                                }
                                else
                                {
                                    txtPrincipalPctOwn.Text = "";
                                }
                            }
                        }

                        if (lblFieldName.Text == "Title")
                        {
                            if (cbConfirmed.Checked)
                            {
                                AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, editMerchant.MerchantPrincipal.Contact.Title, lblNewValue.Text);

                                editMerchant.MerchantPrincipal.Contact.Title = lblNewValue.Text;
                            }
                            else
                            {
                                txtPrincipalTitle.Text = editMerchant.MerchantPrincipal.Contact.Title;
                            }
                        }

                        if (lblFieldName.Text == "DL Number")
                        {
                            if (cbConfirmed.Checked)
                            {
                                String maskedOldDL = MaskDLNumber(editMerchant.MerchantPrincipal.PrincipalDLNumber, editMerchant.MerchantPrincipal.RecordId);

                                Logic.Crypt crypto2 = new Logic.Crypt();
                                crypto2.CryptType = "DL";
                                crypto2.CryptData = Convert.ToBase64String(PWDTK.StringToUtf8Bytes(lblNewValue.Text));
                                crypto2.Purpose = "29dc7202-ae1f-4d38-9694-9d700a94897b";
                                crypto2.AdditionalData = editMerchant.MerchantPrincipal.RecordId.ToString();

                                byte[] newDl = crypto2.Protect();

                                editMerchant.MerchantPrincipal.PrincipalDLNumber = newDl;

                                AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, maskedOldDL, MaskDLNumber(newDl, editMerchant.MerchantPrincipal.RecordId));

                            }
                            else
                            {
                                txtPrincipalDLNumber.Text = MaskDLNumber(editMerchant.MerchantPrincipal.PrincipalDLNumber, editMerchant.MerchantPrincipal.RecordId);
                            }

                            txtPrincipalDLNumber.Enabled = false;
                        }

                        if (lblFieldName.Text == "DL State")
                        {
                            if (cbConfirmed.Checked)
                            {
                                string stateName = editMerchant.MerchantPrincipal.PrincipalDLState == null ? "" : editMerchant.MerchantPrincipal.PrincipalDLState.Name;

                                AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, stateName, lblNewValue.Text);

                                editMerchant.MerchantPrincipal.PrincipalDLState = ctx.GeoStates.First(gs => gs.Name == lblNewValue.Text);
                            }
                            else
                            {
                                if (editMerchant.MerchantPrincipal.PrincipalDLState != null)
                                {
                                    ddlPrincipalDLState.SelectedValue = editMerchant.MerchantPrincipal.PrincipalDLState.RecordId.ToString();
                                }
                                else
                                {
                                    ddlPrincipalDLState.SelectedIndex = -1;
                                }
                            }
                        }

                        if (lblFieldName.Text == "Address")
                        {
                            if (cbConfirmed.Checked)
                            {
                                if (editMerchant.MerchantPrincipal.Contact.Address != null)
                                {
                                    AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, editMerchant.MerchantPrincipal.Contact.Address.Address, lblNewValue.Text);

                                    editMerchant.MerchantPrincipal.Contact.Address.Address = lblNewValue.Text;
                                }
                                else
                                {
                                    AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, "", lblNewValue.Text);

                                    AddressModel newContactAddress = new AddressModel();
                                    newContactAddress.Address = lblNewValue.Text;
                                    ctx.Addresses.Add(newContactAddress);
                                    editMerchant.MerchantPrincipal.Contact.Address = newContactAddress;
                                }
                            }
                            else
                            {
                                if (editMerchant.MerchantPrincipal.Contact.Address != null)
                                {
                                    txtPrincipalAddress.Text = editMerchant.MerchantPrincipal.Contact.Address.Address;
                                }
                                else
                                {
                                    txtPrincipalAddress.Text = "";
                                }
                            }
                        }

                        if (lblFieldName.Text == "City")
                        {
                            if (cbConfirmed.Checked)
                            {
                                if (editMerchant.MerchantPrincipal.Contact.Address != null)
                                {
                                    AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, editMerchant.MerchantPrincipal.Contact.Address.City, lblNewValue.Text);

                                    editMerchant.MerchantPrincipal.Contact.Address.City = lblNewValue.Text;
                                }
                                else
                                {
                                    AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, "", lblNewValue.Text);

                                    AddressModel newContactAddress = new AddressModel();
                                    newContactAddress.City = lblNewValue.Text;
                                    ctx.Addresses.Add(newContactAddress);
                                    editMerchant.MerchantPrincipal.Contact.Address = newContactAddress;
                                }
                            }
                            else
                            {
                                if (editMerchant.MerchantPrincipal.Contact.Address != null)
                                {
                                    txtPrincipalCity.Text = editMerchant.MerchantPrincipal.Contact.Address.City;
                                }
                                else
                                {
                                    txtPrincipalCity.Text = "";
                                }
                            }
                        }

                        if (lblFieldName.Text == "Zip")
                        {
                            if (cbConfirmed.Checked)
                            {
                                if (editMerchant.MerchantPrincipal.Contact.Address != null)
                                {
                                    AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, editMerchant.MerchantPrincipal.Contact.Address.Zip, lblNewValue.Text);

                                    editMerchant.MerchantPrincipal.Contact.Address.Zip = lblNewValue.Text;
                                }
                                else
                                {
                                    AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, "", lblNewValue.Text);

                                    AddressModel newContactAddress = new AddressModel();
                                    newContactAddress.Zip = lblNewValue.Text;
                                    ctx.Addresses.Add(newContactAddress);
                                    editMerchant.MerchantPrincipal.Contact.Address = newContactAddress;
                                }
                            }
                            else
                            {
                                if (editMerchant.MerchantPrincipal.Contact.Address != null)
                                {
                                    txtPrincipalZip.Text = editMerchant.MerchantPrincipal.Contact.Address.Zip;
                                }
                                else
                                {
                                    txtPrincipalZip.Text = "";
                                }
                            }
                        }

                        if (lblFieldName.Text == "State")
                        {
                            if (cbConfirmed.Checked)
                            {
                                if (editMerchant.MerchantPrincipal.Contact.Address != null && editMerchant.MerchantPrincipal.Contact.Address.State != null)
                                {
                                    AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, editMerchant.MerchantPrincipal.Contact.Address.State.Name, lblNewValue.Text);

                                    editMerchant.MerchantPrincipal.Contact.Address.State = ctx.GeoStates.First(gs => gs.Name == lblNewValue.Text);
                                }
                                else
                                {
                                    AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, "", lblNewValue.Text);

                                    AddressModel newContactAddress = new AddressModel();
                                    newContactAddress.State = ctx.GeoStates.First(x => x.Name == lblNewValue.Text);
                                    ctx.Addresses.Add(newContactAddress);
                                    editMerchant.MerchantPrincipal.Contact.Address = newContactAddress;
                                }
                            }
                            else
                            {
                                if (editMerchant.MerchantPrincipal.Contact.Address.State != null)
                                {
                                    ddlPrincipalState.SelectedValue = editMerchant.MerchantPrincipal.Contact.Address.State.RecordId.ToString();
                                }
                                else
                                {
                                    ddlPrincipalState.SelectedIndex = -1;
                                }
                            }
                        }

                        if (lblFieldName.Text == "Home Phone")
                        {
                            if (cbConfirmed.Checked)
                            {
                                AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, editMerchant.MerchantPrincipal.Contact.HomePhone, lblNewValue.Text);

                                editMerchant.MerchantPrincipal.Contact.HomePhone = lblNewValue.Text;
                            }
                            else
                            {
                                txtPrincipalHomePhone.Text = editMerchant.MerchantPrincipal.Contact.HomePhone;
                            }
                        }

                        if (lblFieldName.Text == "Cell Phone")
                        {
                            if (cbConfirmed.Checked)
                            {
                                AddChangeToAudit(editMerchant.RecordId, lblFieldName.Text, editMerchant.MerchantPrincipal.Contact.CellPhone, lblNewValue.Text);

                                editMerchant.MerchantPrincipal.Contact.CellPhone = lblNewValue.Text;
                            }
                            else
                            {
                                txtPrincipalCellPhone.Text = editMerchant.MerchantPrincipal.Contact.CellPhone;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                string userId = "";

                if (Request.IsAuthenticated)
                {
                    userId = Page.User.Identity.GetUserId();
                }
                _newLogic.WriteExceptionToDB(ex, "SavePrincipalChanges", 0, editMerchant.RecordId, userId);
            }
        }
        protected string ShowDLNumber(byte[] dlByte, Int32 principalId)
        {
            string dlNumberOutput;

            try
            {
                if (dlByte != null)
                {
                    Logic.Crypt crypto1 = new Logic.Crypt();
                    crypto1.CryptType = "DL";
                    crypto1.CryptData = PWDTK.Utf8BytesToString(dlByte);
                    crypto1.Purpose = "29dc7202-ae1f-4d38-9694-9d700a94897b";
                    crypto1.AdditionalData = principalId.ToString();

                    byte[] dlBytes = crypto1.Unprotect();

                    return PWDTK.Utf8BytesToString(dlBytes);
                }
                else
                {
                    return null;
                }
            }
            catch (System.Exception ex)
            {
                _newLogic.WriteExceptionToDB(ex, "ShowDLNumber");

                return null;
            }
        }
        protected string ShowSsn(byte[] ssnByte, Int32 principalId)
        {
            try
            {
                if (ssnByte != null)
                {
                    Logic.Crypt crypto2 = new Logic.Crypt();
                    crypto2.CryptType = "SSN";
                    crypto2.CryptData = PWDTK.Utf8BytesToString(ssnByte);
                    crypto2.Purpose = "86d4b5b2-b34a-4968-9fde-f8ed677bca8b";
                    crypto2.AdditionalData = principalId.ToString();

                    byte[] ssnBytes = crypto2.Unprotect();

                    return PWDTK.Utf8BytesToString(ssnBytes);
                }
                else
                {
                    return null;
                }
            }
            catch (System.Exception ex)
            {
                _newLogic.WriteExceptionToDB(ex, "ShowSsn");

                return null;
            }
        }
        protected string ShowDebitCard(byte[] cardByte, Int32 cardId)
        {
            try
            {
                if (cardByte != null)
                {
                    Logic.Crypt crypto1 = new Logic.Crypt();
                    crypto1.CryptType = "Card";
                    crypto1.Purpose = "9c443c6a-87d5-47cc-9c4d-abf6a2bd2e06";
                    crypto1.CryptData = PWDTK.Utf8BytesToString(cardByte);
                    crypto1.AdditionalData = cardId.ToString();

                    byte[] cardNumberBytes = crypto1.Unprotect();

                    return PWDTK.Utf8BytesToString(cardNumberBytes);

                }
                else
                {
                    return null;
                }

            }
            catch (System.Exception ex)
            {
                _newLogic.WriteExceptionToDB(ex, "ShowDebitCard");

                return null;
            }
        }
        protected string ShowAccountNumber(byte[] accountByte, Int32 accountId)
        {
            try
            {
                if (accountByte != null)
                {
                    Logic.Crypt crypto1 = new Logic.Crypt();
                    crypto1.CryptType = "Account";
                    crypto1.Purpose = "4742b06b-9e12-48cf-9034-aadb15dc7a58";
                    crypto1.CryptData = PWDTK.Utf8BytesToString(accountByte);
                    crypto1.AdditionalData = accountId.ToString();

                    byte[] accountNumberBytes = crypto1.Unprotect();

                    return PWDTK.Utf8BytesToString(accountNumberBytes);
                }
                else
                {
                    return null;
                }

            }
            catch (System.Exception ex)
            {
                _newLogic.WriteExceptionToDB(ex, "MaskAccountNumber");

                return null;
            }
        }
        protected string MaskDLNumber(byte[] dlByte, Int32 principalId)
        {
            string dlNumberOutput;

            try
            {
                if (dlByte != null)
                {
                    Logic.Crypt crypto1 = new Logic.Crypt();
                    crypto1.CryptType = "DL";
                    crypto1.CryptData = PWDTK.Utf8BytesToString(dlByte);
                    crypto1.Purpose = "29dc7202-ae1f-4d38-9694-9d700a94897b";
                    crypto1.AdditionalData = principalId.ToString();

                    byte[] dlBytes = crypto1.Unprotect();

                    string dlNumber = PWDTK.Utf8BytesToString(dlBytes);

                    if (!String.IsNullOrEmpty(dlNumber))
                    {
                        if (dlNumber.Length == 1)
                        {
                            dlNumberOutput = "*";
                        }
                        else if (dlNumber.Length == 2)
                        {
                            dlNumberOutput = "**";
                        }
                        else if (dlNumber.Length <= 6)
                        {
                            dlNumberOutput = dlNumber.Substring(0, 1);

                            for (int i = 0; i <= dlNumber.Length - 2; i++)
                            {
                                dlNumberOutput += "*";
                            }

                            dlNumberOutput += dlNumber.Substring(dlNumber.Length - 1, 1);
                        }
                        else
                        {
                            dlNumberOutput = dlNumber.Substring(0, 1);

                            for (int i = 0; i <= dlNumber.Length - 5; i++)
                            {
                                dlNumberOutput += "*";
                            }

                            dlNumberOutput += dlNumber.Substring(dlNumber.Length - 4, 4);
                        }

                        return dlNumberOutput;
                    }
                    else
                    {
                        return null;
                    }
                }
                else
                {
                    return null;
                }
            }
            catch (System.Exception ex)
            {
                _newLogic.WriteExceptionToDB(ex, "MaskDLNumber");

                return null;
            }
        }
        protected string MaskDebitCard(byte[] cardByte, Int32 cardId)
        {
            string cardNumberOutput = "";

            try
            {
                if (cardByte != null)
                {
                    Logic.Crypt crypto1 = new Logic.Crypt();
                    crypto1.CryptType = "Card";
                    crypto1.Purpose = "9c443c6a-87d5-47cc-9c4d-abf6a2bd2e06";
                    crypto1.CryptData = PWDTK.Utf8BytesToString(cardByte);
                    crypto1.AdditionalData = cardId.ToString();

                    byte[] cardNumberBytes = crypto1.Unprotect();

                    string cardNumber = PWDTK.Utf8BytesToString(cardNumberBytes);

                    cardNumberOutput += cardNumber.Substring(0, 6);

                    for (int i = 0; i <= cardNumber.Length - 10; i++)
                    {
                        cardNumberOutput += "*";
                    }

                    cardNumberOutput += cardNumber.Substring(cardNumber.Length - 10, 4);

                    return cardNumberOutput;
                }
                else
                {
                    return null;
                }

            }
            catch (System.Exception ex)
            {
                _newLogic.WriteExceptionToDB(ex, "MaskDebitCard");

                return null;
            }
        }
        protected string MaskAccountNumber(byte[] accountByte, Int32 accountId)
        {
            string accountNumberOutput = "";

            try
            {
                if (accountByte != null)
                {
                    Logic.Crypt crypto1 = new Logic.Crypt();
                    crypto1.CryptType = "Account";
                    crypto1.Purpose = "4742b06b-9e12-48cf-9034-aadb15dc7a58";
                    crypto1.CryptData = PWDTK.Utf8BytesToString(accountByte);
                    crypto1.AdditionalData = accountId.ToString();

                    byte[] accountNumberBytes = crypto1.Unprotect();

                    string accountNumber = PWDTK.Utf8BytesToString(accountNumberBytes);

                    for (int i = 0; i <= accountNumber.Length - 4; i++)
                    {
                        accountNumberOutput += "*";
                    }

                    accountNumberOutput += accountNumber.Substring(accountNumber.Length - 4, 4);

                    return accountNumberOutput;
                }
                else
                {
                    return null;
                }

            }
            catch (System.Exception ex)
            {
                _newLogic.WriteExceptionToDB(ex, "MaskAccountNumber");

                return null;
            }

            return accountNumberOutput;
        }