public static PersonPhone Translate(DataRow row)
        {
            var phone = new PersonPhone();

            try
            {
                var communicationType = row.Field <string>("communication_type");

                if (communicationType != "Mobile" && !communicationType.Contains("Phone") && !communicationType.Contains("phone"))
                {
                    return(null);
                }

                var householdId       = row.Field <int>("household_id");
                var companyAsPersonId = F1Company.GetCompanyAsPersonId(householdId);
                var phoneType         = communicationType.Replace("Phone", string.Empty).Replace("phone", string.Empty).Trim();
                var phoneNumber       = new string( row.Field <string>("communication_value").Where(c => char.IsDigit(c)).ToArray());

                if (!string.IsNullOrWhiteSpace(phoneNumber))
                {
                    phone.PersonId    = companyAsPersonId;
                    phone.PhoneType   = phoneType;
                    phone.PhoneNumber = phoneNumber;
                    return(phone);
                }
            }
            catch
            {
                return(null);
            }

            return(null);
        }
        public static FinancialTransaction Translate(DataRow row, Dictionary <int, HeadOfHousehold> headOfHouseHolds, HashSet <int> companyHouseholdIds)
        {
            var transaction  = new FinancialTransaction();
            var individualId = row.Field <int?>("Individual_ID");
            var householdId  = row.Field <int?>("household_id");
            var isCompany    = householdId.HasValue && companyHouseholdIds.Contains(householdId.Value);

            if (individualId.HasValue)
            {
                transaction.AuthorizedPersonId = individualId.Value;
            }
            else if (isCompany)
            {
                transaction.AuthorizedPersonId = F1Company.GetCompanyAsPersonId(householdId.Value);
            }
            else if (householdId.HasValue && headOfHouseHolds.TryGetValue(householdId.Value, out var headIndividual))
            {
                transaction.AuthorizedPersonId = headIndividual?.IndividualId;
            }

            if (row.Field <int?>("BatchID").HasValue)
            {
                transaction.BatchId = row.Field <int?>("BatchID").Value;
            }
            else
            {
                transaction.BatchId = 90000000 + int.Parse(row.Field <DateTime?>("Received_Date").Value.ToString("yyyyMMdd"));
            }

            transaction.TransactionDate = row.Field <DateTime?>("Received_Date");
            transaction.TransactionCode = row.Field <string>("Check_Number");
            transaction.Summary         = row.Field <string>("Memo");
            transaction.Id = row.Field <int>("ContributionID");

            switch (row.Field <string>("Contribution_Type_Name"))
            {
            case "Cash":
                transaction.CurrencyType = CurrencyType.Cash;
                break;

            case "Check":
                transaction.CurrencyType = CurrencyType.Check;
                break;

            case "Credit Card":
                transaction.CurrencyType = CurrencyType.CreditCard;
                break;

            case "ACH":
                transaction.CurrencyType = CurrencyType.ACH;
                break;

            case "Non-Cash":
                transaction.CurrencyType = CurrencyType.NonCash;
                break;

            default:
                transaction.CurrencyType = CurrencyType.Unknown;
                break;
            }

            var accountId = 0;
            MD5 md5Hasher = MD5.Create();

            byte[] hashed;
            //Set Account Id
            if (string.IsNullOrWhiteSpace(row.Field <string>("sub_fund_name")))
            {
                //Use Hash to create Account ID
                hashed = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(row.Field <string>("fund_name")));
            }
            else
            {
                hashed = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(row.Field <string>("fund_name") + row.Field <string>("sub_fund_name")));
            }

            accountId = Math.Abs(BitConverter.ToInt32(hashed, 0));     // used abs to ensure positive number

            transaction.FinancialTransactionDetails.Add(new FinancialTransactionDetail
            {
                Id            = transaction.Id,
                TransactionId = transaction.Id,
                Amount        = row.Field <decimal>("Amount"),
                AccountId     = accountId
            });

            return(transaction);
        }
Beispiel #3
0
        public static PersonAddress Translate(DataRow row)
        {
            var address = new PersonAddress();

            try
            {
                var householdId       = row.Field <int>("household_id");
                var companyAsPersonId = F1Company.GetCompanyAsPersonId(householdId);

                address.PersonId   = companyAsPersonId;
                address.Street1    = row.Field <string>("address_1");
                address.Street2    = row.Field <string>("address_2");
                address.City       = row.Field <string>("city");
                address.State      = row.Field <string>("state");
                address.PostalCode = row.Field <string>("zip_code");
                address.Country    = row.Field <string>("country");

                var addressType = row.Field <string>("address_type");
                switch (addressType)
                {
                case "Primary":
                {
                    address.AddressType = AddressType.Home;
                    address.IsMailing   = true;
                    break;
                }

                case "Previous":
                {
                    address.AddressType = AddressType.Previous;
                    break;
                }

                case "Business":
                {
                    address.AddressType = AddressType.Work;
                    break;
                }

                case "Mail Returned / Incorrect":
                {
                    address.AddressType = AddressType.Other;
                    break;
                }

                default:
                {
                    address.AddressType = AddressType.Other;
                    break;
                }
                }

                // only add the address if we have a valid address
                if (address.Street1.IsNotNullOrWhitespace() &&
                    address.City.IsNotNullOrWhitespace() &&
                    address.PostalCode.IsNotNullOrWhitespace())
                {
                    return(address);
                }

                return(null);
            }
            catch
            {
                return(null);
            }
        }