Пример #1
0
        private static void UpdateConstituent(Donor d, ref constituent c, string noteHistory = "")
        {
            //update fields
            c.lastName   = d.LName;
            c.firstName  = d.FName;
            c.updateDate = DateTime.Now;

            var request = new SaveOrUpdateConstituentRequest {
                constituent = c
            };
            var response = _client.SaveOrUpdateConstituent(request);
            var nc       = response.constituent;

            AddPhoneToConstituent(d, ref c, true, true);
            AddEmailToConstituent(d, ref c, true, true);

            var billing = d.DonorAddresses.FirstOrDefault(x => x.AddressType == Enum_AddressType.Billing);

            if (billing != null)
            {
                AddAddressToConstituent(billing, ref c, true, true);
            }

            var shipping = d.DonorAddresses.FirstOrDefault(x => x.AddressType == Enum_AddressType.Shipping);

            if (shipping != null)
            {
                AddAddressToConstituent(shipping, ref c, true, true);
            }

            if (!string.IsNullOrEmpty(noteHistory))
            {
                AddCommunicationHistoryToDonor(noteHistory, ref c);
            }
        }
Пример #2
0
        private static void AddPhoneToConstituent(Donor d, ref constituent constt, bool setPrimary = false, bool SendToApi = false)
        {
            try
            {
                var phone = new phone
                {
                    number         = d.Phone,
                    inactive       = false,
                    primary        = setPrimary,
                    createDate     = DateTime.Now,
                    updateDate     = DateTime.Now,
                    customFieldMap = new abstractCustomizableEntityEntry[0],
                };

                //check if is null or already has phone.
                if (constt.phones == null)
                {
                    constt.phones    = new phone[1];
                    constt.phones[0] = phone;
                }
                else
                {
                    var newmax   = constt.phones.Count() + 1;
                    var newArray = new phone[newmax];
                    constt.phones.CopyTo(newArray, 0);
                    newArray[newmax - 1] = phone;
                    constt.phones        = newArray;
                }

                if (SendToApi)
                {
                    var saveOrUpdateConstituentRequest = new SaveOrUpdateConstituentRequest {
                        constituent = constt
                    };
                    _client.SaveOrUpdateConstituent(saveOrUpdateConstituentRequest);
                }
            }
            catch (FaultException exception)
            {
                Type         exType = exception.GetType();
                MessageFault mf     = exception.CreateMessageFault();
                Console.WriteLine("Error when add phone to constituent // " + exception.Message);
                if (mf.HasDetail)
                {
                    var    detailedMessage = mf.GetDetail <System.Xml.Linq.XElement>();
                    String message         = detailedMessage.FirstNode.ToString();
                    Console.WriteLine("More details // " + message);
                }
            }
            catch (Exception exc)
            {
                var txt = exc;
            }
        }
Пример #3
0
        private static void AddEmailToConstituent(Donor d, ref constituent constt, bool setPrimary = false, bool SendToApi = false)
        {
            try
            {
                var email = new email
                {
                    emailAddress   = d.Email,
                    emailDisplay   = d.FullName,
                    primary        = setPrimary,
                    createDate     = DateTime.Now,
                    updateDate     = DateTime.Now,
                    customFieldMap = new abstractCustomizableEntityEntry[0],
                };

                if (constt.emails == null)
                {
                    constt.emails    = new email[1];
                    constt.emails[0] = email;
                }
                else
                {
                    var newmax   = constt.emails.Count() + 1;
                    var newArray = new email[newmax];
                    constt.emails.CopyTo(newArray, 0);
                    newArray[newmax - 1] = email;
                    constt.emails        = newArray;
                }

                if (SendToApi)
                {
                    var saveOrUpdateConstituentRequest = new SaveOrUpdateConstituentRequest {
                        constituent = constt
                    };
                    _client.SaveOrUpdateConstituent(saveOrUpdateConstituentRequest);
                }
            }
            catch (FaultException exception)
            {
                Type         exType = exception.GetType();
                MessageFault mf     = exception.CreateMessageFault();
                Console.WriteLine("Error when adding email to constituent // " + exception.Message);
                if (mf.HasDetail)
                {
                    var    detailedMessage = mf.GetDetail <System.Xml.Linq.XElement>();
                    String message         = detailedMessage.FirstNode.ToString();
                    Console.WriteLine("More details // " + message);
                }
            }
            catch (Exception exc)
            {
                var txt = exc;
            }
        }
Пример #4
0
        private static void AddAddressToConstituent(Address add, ref constituent constt, bool setPrimary = false, bool sendToApi = false)
        {
            try
            {
                var address = TranslateAddress(add, setPrimary);
                address.createDate     = DateTime.Now;
                address.updateDate     = DateTime.Now;
                address.customFieldMap = new abstractCustomizableEntityEntry[0];

                if (constt.addresses == null)
                {
                    constt.addresses    = new address[1];
                    constt.addresses[0] = address;
                }
                else
                {
                    var newmax   = constt.addresses.Count() + 1;
                    var newArray = new address[newmax];
                    constt.addresses.CopyTo(newArray, 0);
                    newArray[newmax - 1] = address;
                    constt.addresses     = newArray;
                }

                if (sendToApi)
                {
                    var saveOrUpdateConstituentRequest = new SaveOrUpdateConstituentRequest {
                        constituent = constt
                    };
                    _client.SaveOrUpdateConstituent(saveOrUpdateConstituentRequest);
                }
            }
            catch (FaultException exception)
            {
                Type         exType = exception.GetType();
                MessageFault mf     = exception.CreateMessageFault();
                Console.WriteLine("Error when adding address to constituent // " + exception.Message);
                if (mf.HasDetail)
                {
                    var    detailedMessage = mf.GetDetail <System.Xml.Linq.XElement>();
                    String message         = detailedMessage.FirstNode.ToString();
                    Console.WriteLine("More details // " + message);
                }
            }
            catch (Exception exc)
            {
                var txt = exc;
            }
        }
Пример #5
0
        private static constituent CreateConstituent(Donor d)
        {
            var constt = new constituent();

            try
            {
                var fieldMap = new abstractCustomizableEntityEntry[2];

                fieldMap[0] = AddSourceCodeToConstintuent(d);
                fieldMap[1] = AddCommunicationPreferences(d);

                constt.firstName       = d.FName;
                constt.lastName        = d.LName;
                constt.constituentType = "individual";
                constt.customFieldMap  = fieldMap;
                constt.inactive        = false;
                constt.createDate      = DateTime.Now;
                constt.updateDate      = DateTime.Now;

                var request = new SaveOrUpdateConstituentRequest {
                    constituent = constt
                };
                var response = _client.SaveOrUpdateConstituent(request);

                return(response.constituent);
            }
            catch (FaultException exception)
            {
                Type         exType = exception.GetType();
                MessageFault mf     = exception.CreateMessageFault();
                Console.WriteLine("Error when creating constituent // " + exception.Message);
                if (mf.HasDetail)
                {
                    var    detailedMessage = mf.GetDetail <System.Xml.Linq.XElement>();
                    String message         = detailedMessage.FirstNode.ToString();
                    Console.WriteLine("More details // " + message);
                }
            }
            catch (Exception exc)
            {
                var txt = exc;
            }
            return(null);
        }
Пример #6
0
        private static void AddCommunicationHistoryToDonor(string note, ref constituent c)
        {
            try
            {
                var req = new SaveOrUpdateCommunicationHistoryRequest();
                req.constituentId = c.id;

                var history = new communicationHistory();
                history.comments = note;
                history.communicationHistoryType = "MANUAL";
                history.constituentId            = c.id;
                history.createDate     = DateTime.Now;
                history.entryType      = "Note"; //pick list during setup, let admin decide.
                history.updateDate     = DateTime.Now;
                history.customFieldMap = new abstractCustomizableEntityEntry[0];

                req.communicationHistory = history;

                var resp = _client.SaveOrUpdateCommunicationHistory(req);
                var his  = resp.communicationHistory;
            }
            catch (FaultException exception)
            {
                Type         exType = exception.GetType();
                MessageFault mf     = exception.CreateMessageFault();
                Console.WriteLine("Error when add phone to constituent // " + exception.Message);
                if (mf.HasDetail)
                {
                    var    detailedMessage = mf.GetDetail <System.Xml.Linq.XElement>();
                    String message         = detailedMessage.FirstNode.ToString();
                    Console.WriteLine("More details // " + message);
                }
            }
            catch (Exception exc)
            {
                var txt = exc;
            }
        }
Пример #7
0
        private static void AddGiftToConstituent(Donation donation, ref constituent constt)
        {
            /* 12/16/2014
             * For now, send all of our donations over as "CASH" until OLOD's API can handle pre-processed donations.            *
             *
             */

            try
            {
                var g        = new gift();
                var ps       = new paymentSource();
                var fieldMap = new abstractCustomizableEntityEntry[1];
                fieldMap[0] = createCustomFieldMap("source", 0, constt.id, "source", "source", donation.SourceCode);

                ps.paymentType   = PaymentType.Cash;
                ps.constituentId = constt.id;
                g.paymentSource  = ps;

                var billing = donation.Donor.DonorAddresses.FirstOrDefault(x => x.AddressType == Enum_AddressType.Billing);
                var nowDate = DateTime.Now;

                g.createDate   = nowDate;
                g.updateDate   = nowDate;
                g.currencyCode = "USD";


                g.address  = TranslateAddress(billing, false);
                g.amount   = donation.Amount;
                g.comments = "Processed by RaiseDonors using card ending in x" + donation.Last4ofCC;
                if (!string.IsNullOrEmpty(donation.Comment))
                {
                    g.comments += "Donor provided comment: " + donation.Comment;
                }
                g.customFieldMap           = fieldMap;
                g.constituentId            = constt.id;
                g.deductible               = false;
                g.deductibleAmount         = 0.00m;
                g.donationDate             = nowDate;
                g.email                    = constt.primaryEmail;
                g.giftStatus               = "Paid"; //Paid, Pending, Not Paid
                g.paymentType              = PaymentType.Cash;
                g.phone                    = constt.primaryPhone;
                g.transactionDate          = nowDate;
                g.transactionDateSpecified = true;

                //conditionally hide these -- wait for paul's response on what is best.
                //g.paymentStatus = "";
                g.paymentMessage = "Processed thru RaiseDonors";
                g.authCode       = donation.AuthorizationNumber;
                g.txRefNum       = donation.TransactionId;


                var distLines = new List <distributionLine>();
                foreach (var d in donation.DonationFundAllocations)
                {
                    //read project codes, and use in setup on which one to use.
                    var fieldMaps = new List <abstractCustomizableEntityEntry>
                    {
                        createCustomFieldMap("anonymous", 0, constt.id, "distributionline", "anonymous", "false"),
                        createCustomFieldMap("recognitionName", 0, constt.id, "distributionline", "recognitionName", donation.Donor.FullName),
                        createCustomFieldMap("totalAdjustedAmount", 0, constt.id, "distributionline", "totalAdjustedAmount", d.Amount.ToString("0.00")),
                        createCustomFieldMap("taxDeductible", 0, constt.id, "distributionline", "taxDeductible", "true"),
                    };

                    var dLine = new distributionLine
                    {
                        customFieldMap       = fieldMaps.ToArray(),
                        amount               = d.Amount,
                        amountSpecified      = true,
                        other_motivationCode = donation.MotivationCode,
                        //percentage = Math.Round((d.Amount / donation.Amount) * 100, 2, MidpointRounding.AwayFromZero),
                        //motivationCode = donation.MotivationCode,  //what motivated to give - don't use this one
                        projectCode = d.Fund.Name //gift designation?
                    };
                    distLines.Add(dLine);
                }

                //source-code, use customfield on the gift.
                //project, and source will throw error if not pre-existing.

                //throws error
                //Value cannot be null.
                //Parameter name: source
                g.distributionLines = distLines.ToArray();

                var request = new SaveOrUpdateGiftRequest {
                    gift = g, constituentId = constt.id
                };
                var response = _client.SaveOrUpdateGift(request);

                Console.WriteLine("Successfully sent gift to OLOD, gift ID: " + response.gift.id + ".");
            }
            catch (FaultException exception)
            {
                Type         exType = exception.GetType();
                MessageFault mf     = exception.CreateMessageFault();
                Console.WriteLine("Error when adding gift to constituent // " + exception.Message);
                if (mf.HasDetail)
                {
                    var    detailedMessage = mf.GetDetail <System.Xml.Linq.XElement>();
                    String message         = detailedMessage.FirstNode.ToString();
                    Console.WriteLine("More details // " + message);
                }
            }
            catch (Exception exc)
            {
                var text = exc;
            }
        }