public void UploadNewPinToAws(PinDto pin) { var cloudSearch = new AmazonCloudSearchDomainClient(AwsAccessKeyId, AwsSecretAccessKey, AmazonSearchUrl); var upload = GetObjectToUploadToAws(pin); cloudSearch.UploadDocuments(upload); }
private string GenerateAwsPinId(PinDto pin) { if (pin.PinType == PinType.GATHERING) { return(GenerateAwsPinString(pin, pin.Gathering.Address.AddressID.ToString(), pin.Gathering.GroupId.ToString())); } else { return(GenerateAwsPinString(pin, pin.Address.AddressID.ToString())); } }
public void ShouldUpdateHouseholdAddress() { var pin = new PinDto { Address = new AddressDTO { AddressID = 741, AddressLine1 = "123 Main Street", City = "Cincinnati", State = "OH", PostalCode = "45249" }, Contact_ID = 123, Participant_ID = 456, Household_ID = 789, EmailAddress = "", FirstName = "", LastName = "", Gathering = null, Host_Status_ID = 0 }; var geoCodes = new GeoCoordinate() { Altitude = 0, Course = 0, HorizontalAccuracy = 0, Latitude = 10, Longitude = 20, Speed = 0, VerticalAccuracy = 0 }; var addressDictionary = new Dictionary <string, object> { { "AddressID", pin.Address.AddressID }, { "AddressLine1", pin.Address.AddressID }, { "City", pin.Address.AddressID }, { "State/Region", pin.Address.AddressID }, { "PostCode", pin.Address.AddressID } }; var householdDictionary = new Dictionary <string, object> { { "Household_ID", pin.Household_ID } }; _addressGeocodingService.Setup(mocked => mocked.GetGeoCoordinates(It.IsAny <AddressDTO>())).Returns(geoCodes); _addressService.Setup(m => m.SetGeoCoordinates(pin.Address)); _mpContactRepository.Setup(m => m.UpdateHouseholdAddress((int)pin.Household_ID, householdDictionary, addressDictionary)); _addressService.Setup(m => m.GetGeoLocationCascading(It.IsAny <AddressDTO>())).Returns(new GeoCoordinate(39, -84)); _fixture.UpdateHouseholdAddress(pin); _mpFinderRepository.VerifyAll(); }
public void SetGroupPinGeoCoordinates(PinDto pin) { try { var coordinates = this.GetGeoLocationCascading(pin.Gathering.Address); pin.Address.Latitude = coordinates.Latitude; pin.Address.Longitude = coordinates.Longitude; var mpAddress = AutoMapper.Mapper.Map <MpAddress>(pin.Gathering.Address); UpdateAddress(mpAddress); } catch (InvalidAddressException e) { _logger.Info($"Can't get GeoCoordinates for address '{pin.Gathering.Address}', address is invalid", e); } catch (Exception e) { _logger.Error($"Error getting GeoCoordinates for address '{pin.Gathering.Address}'", e); } }
public UploadDocumentsRequest GetObjectToUploadToAws(PinDto pin) { AwsConnectDto awsPinObject = Mapper.Map <AwsConnectDto>(pin); if (pin.PinType == PinType.GATHERING) { awsPinObject.AddressId = pin.Gathering.Address.AddressID; awsPinObject.Latitude = pin.Gathering.Address.Latitude; awsPinObject.Longitude = pin.Gathering.Address.Longitude; awsPinObject.City = pin.Gathering.Address.City; awsPinObject.LatLong = (pin.Gathering.Address.Latitude == null || pin.Gathering.Address.Longitude == null) ? "0 , 0" : $"{pin.Gathering.Address.Latitude} , {pin.Gathering.Address.Longitude}"; awsPinObject.State = pin.Gathering.Address.State; awsPinObject.Zip = pin.Gathering.Address.PostalCode; awsPinObject.GroupStartDate = pin.Gathering.StartDate; awsPinObject.GroupId = pin.Gathering.GroupId; awsPinObject.GroupTypeId = pin.Gathering.GroupTypeId; awsPinObject.GroupDescription = pin.Gathering.GroupDescription; awsPinObject.GroupName = pin.Gathering.GroupName; } AwsCloudsearchDto awsPostPinObject = new AwsCloudsearchDto("add", GenerateAwsPinId(pin), awsPinObject); var pinlist = new List <AwsCloudsearchDto> { awsPostPinObject }; string jsonAwsObject = JsonConvert.SerializeObject(pinlist, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); MemoryStream jsonAwsPinDtoStream = new MemoryStream(Encoding.UTF8.GetBytes(jsonAwsObject)); UploadDocumentsRequest upload = new UploadDocumentsRequest() { ContentType = ContentType.ApplicationJson, Documents = jsonAwsPinDtoStream }; return(upload); }
public IHttpActionResult PostPin([FromBody] PinDto pin) { return(Authorized(token => { try { if (pin.Address != null && string.IsNullOrEmpty(pin.Address.AddressLine1) == false) { _finderService.UpdateHouseholdAddress(pin); } if (pin.Participant_ID == 0 || String.IsNullOrEmpty(pin.Participant_ID.ToString())) { pin.Participant_ID = _finderService.GetParticipantIdFromContact((int)pin.Contact_ID); } _finderService.EnablePin((int)pin.Participant_ID); _logger.DebugFormat("Successfully created pin for contact {0} ", pin.Contact_ID); //Ensure that address id is available var personPin = _finderService.GetPinDetailsForPerson((int)pin.Participant_ID); //Call analytics var props = new EventProperties { { "City", pin?.Address?.City }, { "State", pin?.Address?.State }, { "Zip", pin?.Address?.PostalCode } }; _analyticsService.Track(pin.Contact_ID.ToString(), "AddedtoMap", props); _awsCloudsearchService.UploadNewPinToAws(personPin); return (Ok(pin)); } catch (Exception e) { _logger.Error("Could not create pin", e); var apiError = new ApiErrorDto("Save Pin Failed", e); throw new HttpResponseException(apiError.HttpResponseMessage); } })); }
private static List <PinDto> GetListOfPinDto() { var list = new List <PinDto>(); var addr1 = new AddressDTO { Latitude = 30.1, Longitude = -80.1 }; var pin1 = new PinDto { Contact_ID = 1, EmailAddress = "*****@*****.**", FirstName = "pinhead", LastName = "One", Address = addr1 }; var addr2 = new AddressDTO { Latitude = 30.2, Longitude = -80.2 }; var pin2 = new PinDto { Contact_ID = 2, EmailAddress = "*****@*****.**", FirstName = "pinhead", LastName = "Two", Address = addr2 }; list.Add(pin1); list.Add(pin2); return(list); }
public IHttpActionResult EditGatheringPin([FromBody] PinDto pin) { return(Authorized(token => { try { if (pin.Contact_ID != _authenticationRepo.GetContactId(token)) { throw new HttpResponseException(HttpStatusCode.Unauthorized); } pin = _finderService.UpdateGathering(pin); _awsCloudsearchService.UploadNewPinToAws(pin); return (Ok(pin)); } catch (Exception e) { _logger.Error("Could not update pin", e); var apiError = new ApiErrorDto("Save Pin Failed", e); throw new HttpResponseException(apiError.HttpResponseMessage); } })); }
private string GenerateAwsPinString(PinDto pin, string addressId, string groupId = "") { return(addressId + "-" + (int)pin.PinType + '-' + pin.Participant_ID + "-" + groupId); }
private FinderPinDto convertPinDtoToFinderPinDto(PinDto pinDto) { return(Mapper.Map <FinderPinDto>(pinDto)); }