private void MapAddressFields()
 {
     Address = new MpAddress();
     if (_unmappedData.ContainsKey("Address_Line_1"))
     {
         Address.Address_Line_1 = _unmappedData["Address_Line_1"].Value <string>();
     }
     if (_unmappedData.ContainsKey("City"))
     {
         Address.City = _unmappedData["City"].Value <string>();
     }
     if (_unmappedData.ContainsKey("State"))
     {
         Address.State = _unmappedData["State"].Value <string>();
     }
     if (_unmappedData.ContainsKey("Postal_Code"))
     {
         Address.Postal_Code = _unmappedData["Postal_Code"].Value <string>();
     }
     if (_unmappedData.ContainsKey("Longitude"))
     {
         Address.Longitude = _unmappedData["Longitude"].Value <double?>();
     }
     if (_unmappedData.ContainsKey("Latitude"))
     {
         Address.Latitude = _unmappedData["Latitude"].Value <double?>();
     }
 }
Пример #2
0
        public List <MpAddress> FindMatches(MpAddress address)
        {
            var apiToken = _apiUserService.GetToken();
            var search   = string.Format("{0}, {1}, {2}, {3}, {4}, {5}",
                                         AddQuotesIfNotEmpty(address.Address_Line_1),
                                         AddQuotesIfNotEmpty(address.Address_Line_2),
                                         AddQuotesIfNotEmpty(address.City),
                                         AddQuotesIfNotEmpty(address.State),
                                         AddQuotesIfNotEmpty(address.Postal_Code),
                                         AddQuotesIfNotEmpty(address.Foreign_Country));

            var records = _ministryPlatformService.GetPageViewRecords(_addressApiPageViewId, apiToken, search);

            object longitudeObj;
            object latitudeObj;
            double latitude;
            double longitude;
            var    addresses = records.Select(record => new MpAddress()
            {
                Address_ID      = record.ToInt("dp_RecordID"),
                Address_Line_1  = record.ToString("Address_Line_1"),
                Address_Line_2  = record.ToString("Address_Line_2"),
                City            = record.ToString("City"),
                State           = record.ToString("State/Region"),
                Postal_Code     = record.ToString("Postal_Code"),
                Foreign_Country = record.ToString("Foreign_Country"),
                Latitude        = record.TryGetValue("Latitude", out latitudeObj) && latitudeObj != null && double.TryParse(latitudeObj.ToString(), out latitude) ? latitude : (double?)null,
                Longitude       = record.TryGetValue("Longitude", out longitudeObj) && longitudeObj != null && double.TryParse(longitudeObj.ToString(), out longitude) ? longitude : (double?)null,
            }).ToList();

            return(addresses);
        }
Пример #3
0
        public void getFinderPinDetails()
        {
            var participantId = 123;

            var response = new FinderPinDto
            {
                Address        = null,
                LastName       = "Kerstanoff",
                Contact_ID     = 12,
                EmailAddress   = "*****@*****.**",
                FirstName      = "Joe",
                Household_ID   = 2,
                Participant_ID = 123
            };
            var addressResponse = new MpAddress {
                Address_ID = 1, Address_Line_1 = "123 street", City = "City!", Postal_Code = "12345"
            };

            _apiUserRepo.Setup(m => m.GetToken()).Returns("abc");
            _ministryPlatformRestRepository.Setup(
                mocked =>
                mocked.Search <FinderPinDto>(
                    It.Is <string>(
                        m =>
                        m.Equals(
                            $"Participant_Record = {participantId}")),
                    It.Is <string>(
                        m =>
                        m.Equals(
                            "Email_Address, Nickname as FirstName, Last_Name as LastName, Participant_Record_Table.*, Household_ID")),
                    It.IsAny <string>(),
                    It.IsAny <bool>())).Returns(new List <FinderPinDto> {
                response
            });

            _ministryPlatformRestRepository.Setup(
                mocked =>
                mocked.Search <MpAddress>(
                    It.Is <string>(
                        m =>
                        m.Equals(
                            $"Participant_Record = {participantId}")),
                    It.Is <string>(
                        m =>
                        m.Equals(
                            "Household_ID_Table_Address_ID_Table.*")),
                    It.IsAny <string>(),
                    It.IsAny <bool>())).Returns(new List <MpAddress> {
                addressResponse
            });

            var value = _fixture.GetPinDetails(123);

            _ministryPlatformRestRepository.VerifyAll();

            Assert.AreEqual(value.LastName, response.LastName);
            Assert.AreEqual(value.Address.Address_ID, response.Address.Address_ID);
        }
Пример #4
0
        public int Create(MpAddress address)
        {
            var apiToken = _apiUserService.GetToken();

            var values = MapAddressDictionary(address);

            var addressId = _ministryPlatformService.CreateRecord(_addressPageId, values, apiToken);

            return(addressId);
        }
Пример #5
0
        public int Update(MpAddress address)
        {
            var apiToken = _apiUserService.GetToken();

            var values = MapAddressDictionary(address);

            values.Add("Address_ID", address.Address_ID.Value);

            _ministryPlatformService.UpdateRecord(_addressPageId, values, apiToken);

            return(address.Address_ID.Value);
        }
Пример #6
0
        public void FindMatches()
        {
            var addrRecords = new List <Dictionary <string, object> >()
            {
                new Dictionary <string, object>()
                {
                    { "dp_RecordID", 12345 },
                    { "Address_Line_1", "321 Road Ln" },
                    { "Address_Line_2", "Suite 100" },
                    { "City", "Madison" },
                    { "State/Region", "OH" },
                    { "Postal_Code", "45454" },
                    { "Foreign_Country", "USA" },
                    { "County", "Hamilton" },
                    { "Longitude", "123.45" },
                    { "Latitude", "678.90" },
                }
            };

            var addr = new MpAddress()
            {
                Address_ID      = 12345,
                Address_Line_1  = "321 Road Ln",
                Address_Line_2  = "Suite 100",
                City            = "Madison",
                State           = "OH",
                Postal_Code     = "45454",
                Foreign_Country = "USA",
                County          = "Hamilton",
                Longitude       = 123.45,
                Latitude        = 678.90
            };

            _ministryPlatformService.Setup(m => m.GetPageViewRecords(_addressApiPageViewId, It.IsAny <string>(), It.IsAny <string>(), string.Empty, 0)).Returns(addrRecords);

            var records = _fixture.FindMatches(addr);

            _ministryPlatformService.VerifyAll();
            Assert.IsNotNull(records);
            Assert.AreEqual(addr.Address_ID, records[0].Address_ID);
            Assert.AreEqual(addr.Address_Line_1, records[0].Address_Line_1);
            Assert.AreEqual(addr.Address_Line_2, records[0].Address_Line_2);
            Assert.AreEqual(addr.City, records[0].City);
            Assert.AreEqual(addr.State, records[0].State);
            Assert.AreEqual(addr.Postal_Code, records[0].Postal_Code);
            Assert.AreEqual(addr.Longitude, records[0].Longitude);
            Assert.AreEqual(addr.Latitude, records[0].Latitude);
        }
Пример #7
0
 protected override void ProcessUnmappedData(IDictionary <string, JToken> unmappedData, StreamingContext context)
 {
     if (Address == null)
     {
         Address = new MpAddress();
     }
     Address.Address_ID      = unmappedData.GetUnmappedDataField <int>("Address_ID");
     Address.Address_Line_1  = unmappedData.GetUnmappedDataField <string>("Address_Line_1");
     Address.Address_Line_2  = unmappedData.GetUnmappedDataField <string>("Address_Line_2");
     Address.City            = unmappedData.GetUnmappedDataField <string>("City");
     Address.State           = unmappedData.GetUnmappedDataField <string>("State/Region");
     Address.Postal_Code     = unmappedData.GetUnmappedDataField <string>("Postal_Code");
     Address.Foreign_Country = unmappedData.GetUnmappedDataField <string>("Foreign_Country");
     Address.Longitude       = Convert.ToDouble(unmappedData.GetUnmappedDataField <string>("Longitude"));
     Address.Latitude        = Convert.ToDouble(unmappedData.GetUnmappedDataField <string>("Latitude"));
 }
Пример #8
0
        public MpAddress GetAddressById(string token, int id)
        {
            var record = _ministryPlatformService.GetRecordDict(_addressPageId, id, token);

            var address = new MpAddress()
            {
                Address_ID     = record.ToInt("Address_ID"),
                Address_Line_1 = record.ToString("Address_Line_1"),
                Address_Line_2 = record.ToString("Address_Line_2"),
                City           = record.ToString("City"),
                State          = record.ToString("State/Region"),
                Postal_Code    = record.ToString("Postal_Code")
            };

            return(address);
        }
Пример #9
0
        private static Dictionary <string, object> MapAddressDictionary(MpAddress address)
        {
            var values = new Dictionary <string, object>()
            {
                { "Address_Line_1", address.Address_Line_1 },
                { "Address_Line_2", address.Address_Line_2 },
                { "City", address.City },
                { "State/Region", address.State },
                { "Postal_Code", address.Postal_Code },
                { "Foreign_Country", address.Foreign_Country },
                { "County", address.County },
                { "Longitude", address.Longitude },
                { "Latitude", address.Latitude }
            };

            return(values);
        }
Пример #10
0
        public void UpdateAddress()
        {
            const string apiToken  = "useme";
            const int    addressId = 785645;

            var addr = new MpAddress
            {
                Address_ID      = addressId,
                Address_Line_1  = "321 Road Ln",
                Address_Line_2  = "Suite 100",
                City            = "Madison",
                State           = "OH",
                Postal_Code     = "45454",
                Foreign_Country = "USA",
                County          = "Hamilton",
                Longitude       = 123.45,
                Latitude        = 678.90
            };

            _ministryPlatformService.Setup(m => m.UpdateRecord(271, It.IsAny <Dictionary <string, object> >(), apiToken));

            var addrId = _fixture.Update(addr);

            _ministryPlatformService.Verify(
                mocked =>
                mocked.UpdateRecord(_addressPageId,
                                    It.Is <Dictionary <string, object> >(
                                        d =>
                                        d["Address_ID"].Equals(addr.Address_ID) &&
                                        d["Address_Line_1"].Equals(addr.Address_Line_1) &&
                                        d["Address_Line_2"].Equals(addr.Address_Line_2) &&
                                        d["City"].Equals(addr.City) &&
                                        d["State/Region"].Equals(addr.State) &&
                                        d["Postal_Code"].Equals(addr.Postal_Code) &&
                                        d["Foreign_Country"].Equals(addr.Foreign_Country) &&
                                        d["County"].Equals(addr.County) &&
                                        d["Longitude"].Equals(addr.Longitude) &&
                                        d["Latitude"].Equals(addr.Latitude)
                                        ),
                                    "useme"));

            Assert.IsNotNull(addrId);
            Assert.AreEqual(addressId, addrId);
        }
Пример #11
0
        private bool FindExistingAddress(AddressDTO address, MpAddress mpAddress)
        {
            var result = _mpAddressService.FindMatches(mpAddress);

            if (result.Count > 0)
            {
                var found = result.First(x => x.Address_ID.HasValue);
                if (found == null)
                {
                    return(false);
                }
                address.AddressID = found.Address_ID;
                address.Latitude  = found.Latitude;
                address.Longitude = found.Longitude;
                return(true);
            }

            return(false);
        }
Пример #12
0
        public void CreateAddress()
        {
            const string apiToken  = "useme";
            const int    addressId = 785645;

            var addr = new MpAddress()
            {
                Address_Line_1  = "321 Road Ln",
                Address_Line_2  = "Suite 100",
                City            = "Madison",
                State           = "OH",
                Postal_Code     = "45454",
                Foreign_Country = "USA",
                County          = "Hamilton",
                Longitude       = 123.45,
                Latitude        = 678.90
            };

            var values = new Dictionary <string, object>
            {
                { "Address_Line_1", "321 Road Ln" },
                { "Address_Line_2", "Suite 100" },
                { "City", "Madison" },
                { "State/Region", "OH" },
                { "Postal_Code", "45454" },
                { "Foreign_Country", "USA" },
                { "County", "Hamilton" },
                { "Longitude", addr.Longitude },
                { "Latitude", addr.Latitude }
            };

            _ministryPlatformService.Setup(m => m.CreateRecord(_addressPageId, It.IsAny <Dictionary <string, object> >(), apiToken, false)).Returns(addressId);

            int addrId = _fixture.Create(addr);

            _ministryPlatformService.Verify(mocked => mocked.CreateRecord(_addressPageId, values, "useme", false));

            Assert.IsNotNull(addrId);
            Assert.AreEqual(addressId, addrId);
        }
Пример #13
0
 private int UpdateAddress(MpAddress address)
 {
     return(_mpAddressService.Update(address));
 }
Пример #14
0
 private int CreateAddress(MpAddress address)
 {
     return(_mpAddressService.Create(address));
 }