コード例 #1
0
ファイル: Program.cs プロジェクト: mexner/olod
        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
ファイル: Program.cs プロジェクト: mexner/olod
        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
ファイル: Program.cs プロジェクト: mexner/olod
        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
ファイル: Program.cs プロジェクト: mexner/olod
        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
ファイル: Program.cs プロジェクト: mexner/olod
        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);
        }