Exemplo n.º 1
0
        private async Task <List <AdditonalQuestionData> > GetAdditonalQuestionDataForGroupLocationSource(int?groupId)
        {
            List <AdditonalQuestionData> data = new List <AdditonalQuestionData>();

            if (groupId.HasValue)
            {
                var groupLocations = await _groupService.GetGroupLocations(groupId.Value);

                if (groupLocations.Locations.Count() > 0)
                {
                    GetLocationsRequest locationRequest = new GetLocationsRequest()
                    {
                        LocationsRequests = new HelpMyStreet.Contracts.AddressService.Request.LocationsRequest()
                        {
                            Locations = groupLocations.Locations.ToList()
                        }
                    };
                    var details = await _addressService.GetLocations(locationRequest);

                    if (details != null)
                    {
                        data = details.LocationDetails.Select(x => new AdditonalQuestionData()
                        {
                            Key = ((int)x.Location).ToString(), Value = x.ShortName
                        }).ToList();
                    }
                }
            }
            return(data);
        }
Exemplo n.º 2
0
        public IEnumerable <LocationApiModel> GetLocations([FromUri] GetLocationsRequest request)
        {
            var key       = JsonConvert.SerializeObject(request);
            var locations = _cache.Get(key, () => _locationService.GetLocations(request));

            return(Mapper.Map <IEnumerable <LocationApiModel> >(locations).ToList());
        }
Exemplo n.º 3
0
        public async Task <ActionResult <GetLocationsResponse> > GetLocations([FromQuery] GetLocationsRequest request)
        {
            IEnumerable <string> permissedLocations = null;

            if (request == null)
            {
                return(BadRequest(new GetLocationsResponse()));
            }

            if (request.CreateExaminationOnly)
            {
                permissedLocations = await LocationsWithPermission(Permission.CreateExamination);
            }
            else if (request.AccessOnly)
            {
                permissedLocations = await LocationsWithPermission(Permission.GetLocation);
            }

            var locations =
                await _locationRetrievalByQueryHandler.Handle(
                    new LocationsRetrievalByQuery(request.Name, request.ParentId, false, request.OnlyMEOffices, permissedLocations));

            return(Ok(new GetLocationsResponse
            {
                Locations = locations.Select(e => Mapper.Map <LocationItem>(e)).ToList(),
            }));
        }
Exemplo n.º 4
0
        public void GetLocations_ShouldReturnLocations()
        {
            // Arrange
            var expectedName      = "name";
            var expectedLocation1 = new Location
            {
                Name = expectedName,
            };
            var expectedLocations = new List <Location>
            {
                expectedLocation1,
            };

            _locationRetrievalMock
            .Setup(lr => lr.Handle(It.IsAny <LocationsRetrievalByQuery>()))
            .Returns(Task.FromResult((IEnumerable <Location>)expectedLocations));

            var request = new GetLocationsRequest
            {
                Name = expectedName,
            };

            // Act
            var response = Controller.GetLocations(request);

            // Assert
            var taskResult = response.Should().BeOfType <Task <ActionResult <GetLocationsResponse> > >().Subject;
            var okResult   = taskResult.Result.Result.Should().BeAssignableTo <OkObjectResult>().Subject;
            var location   = okResult.Value.Should().BeAssignableTo <GetLocationsResponse>().Subject;

            location.Locations.Count().Should().Be(1);
            location.Locations.First().Name.Should().Be(expectedName);
        }
Exemplo n.º 5
0
        public override async Task GetLocations(GetLocationsRequest request, IServerStreamWriter <GetLocationsResponse> responseStream, ServerCallContext context)
        {
            try
            {
                _logger.LogInformation("Incoming request for GetLocationData");

                var locationData = await GetLocationData();

                var locationDataCount = locationData.Locations.Count;

                var dataLimit = request.DataLimit > locationDataCount ? locationDataCount : request.DataLimit;
                var random    = new Random();

                for (var i = 0; i <= dataLimit - 1; i++)
                {
                    var item = locationData.Locations[i];

                    await responseStream.WriteAsync(new GetLocationsResponse
                    {
                        LatitudeE7  = item.LatitudeE7,
                        LongitudeE7 = item.LongitudeE7
                    });
                }
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, "Error occurred");
                throw;
            }
        }
Exemplo n.º 6
0
        public async Task <GetLocationsResponse> GetLocations(GetLocationsRequest request)
        {
            string path         = $"/api/GetLocations";
            string absolutePath = $"{path}";
            var    jsonContent  = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");

            using (HttpResponseMessage response = await _httpClientWrapper.PostAsync(HttpClientConfigName.AddressService, absolutePath, jsonContent, CancellationToken.None).ConfigureAwait(false))
            {
                string jsonResponse = await response.Content.ReadAsStringAsync();

                var getJobsResponse = JsonConvert.DeserializeObject <ResponseWrapper <GetLocationsResponse, AddressServiceErrorCode> >(jsonResponse);
                if (getJobsResponse.HasContent && getJobsResponse.IsSuccessful)
                {
                    return(getJobsResponse.Content);
                }
                return(null);
            }
        }
Exemplo n.º 7
0
            /// <summary>
            /// Handle
            /// </summary>
            /// <param name="request"></param>
            /// <param name="cancellationToken"></param>
            /// <returns></returns>
            public override async Task <List <GetLocationsSecurityResponse> > Handle(GetLocationsRequest request, CancellationToken cancellationToken)
            {
                List <Localizacion> dpts = await repository.GetAll().ToListAsync().ConfigureAwait(false);

                dpts = dpts.OrderBy(c => c.Nombre).ToList();

                var result = dpts.Select(dpt => new GetLocationsSecurityResponse()
                {
                    IdLocation = dpt.Id,
                    Ciudad     = dpt.Ciudad,
                    CodPostasl = dpt.CodigoPostal,
                    Direccion  = dpt.Direccion1,
                    Name       = dpt.Nombre,
                    Pais       = dpt.Pais
                }).ToList();

                SendTimeOperationToLogger("GetLocations");

                return(result);
            }
Exemplo n.º 8
0
        private async Task AddPostCodeForLocations(List <JobDTO> allJobs)
        {
            //add postcode for locations if locations exist
            List <Location?> distinctLocations = allJobs
                                                 .Where(x => x.Location != null)
                                                 .Select(x => x.Location)
                                                 .Distinct().ToList();
            List <LocationDetails> locationDetails = new List <LocationDetails>();

            if (distinctLocations.Count > 0)
            {
                GetLocationsRequest locationRequest = new GetLocationsRequest()
                {
                    LocationsRequests = new HelpMyStreet.Contracts.AddressService.Request.LocationsRequest()
                    {
                        Locations = distinctLocations.Select(x => x.Value).ToList()
                    }
                };
                var details = await _addressService.GetLocations(locationRequest);

                if (details != null)
                {
                    locationDetails = details.LocationDetails;
                }
            }

            if (locationDetails.Count > 0)
            {
                foreach (JobDTO j in allJobs.Where(x => x.Location != null))
                {
                    var location = locationDetails.First(x => x.Location == j.Location);

                    if (location != null)
                    {
                        j.PostCode = location.Address.Postcode;
                    }
                }
            }
        }
Exemplo n.º 9
0
            /// <summary>
            /// Handle
            /// </summary>
            /// <param name="request"></param>
            /// <param name="cancellationToken"></param>
            /// <returns></returns>
            public override async Task <List <GetLocationsResponse> > Handle(GetLocationsRequest request, CancellationToken cancellationToken)
            {
                Expression <Func <Localizacion, bool> > query = l => true;

                if (!string.IsNullOrWhiteSpace(request.CountryName))
                {
                    query = query.And(l => l.Pais.Trim().ToUpper() == request.CountryName);
                }
                if (request.IdRegion.HasValue)
                {
                    query = query.And(l => l.Area.IdRegion == request.IdRegion.Value);
                }
                if (request.IdArea.HasValue)
                {
                    query = query.And(l => l.IdArea == request.IdArea.Value);
                }

                List <Localizacion> dpts = await repository.GetAll()
                                           .Include(l => l.Area)
                                           .Where(query)
                                           .OrderBy(c => c.Nombre)
                                           .ToListAsync().ConfigureAwait(false);

                var result = dpts.Select(dpt => new GetLocationsResponse()
                {
                    IdLocation = dpt.Id,
                    Ciudad     = dpt.Ciudad,
                    CodPostasl = dpt.CodigoPostal,
                    Direccion  = dpt.Direccion1,
                    Name       = dpt.Nombre,
                    Pais       = dpt.Pais,
                    IdArea     = dpt.IdArea,
                    IdRegion   = dpt.Area?.IdRegion
                }).ToList();

                SendTimeOperationToLogger("GetLocations");

                return(result);
            }
Exemplo n.º 10
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]
            [RequestBodyType(typeof(GetLocationsRequest), "Get Locations")] GetLocationsRequest req,
            CancellationToken cancellationToken)
        {
            try
            {
                var input = JsonConvert.SerializeObject(req);
                _logger.LogInformation(input);
                GetLocationsResponse response = await _mediator.Send(req, cancellationToken);

                return(new OkObjectResult(ResponseWrapper <GetLocationsResponse, AddressServiceErrorCode> .CreateSuccessfulResponse(response)));
            }
            catch (Exception exc)
            {
                _logger.LogErrorAndNotifyNewRelic("Exception occured in GetLocations", exc);
                _logger.LogError(exc.ToString(), exc);
                return(new ObjectResult(ResponseWrapper <GetLocationsResponse, AddressServiceErrorCode> .CreateUnsuccessfulResponse(AddressServiceErrorCode.UnhandledError, "Internal Error"))
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }
Exemplo n.º 11
0
        public async Task <List <LocationDetails> > GetLocationDetails(IEnumerable <Location> locations)
        {
            var getLocationRequest = new GetLocationsRequest
            {
                LocationsRequests = new LocationsRequest
                {
                    Locations = locations.ToList()
                }
            };

            string              json     = JsonConvert.SerializeObject(getLocationRequest);
            StringContent       data     = new StringContent(json, Encoding.UTF8, "application/json");
            HttpResponseMessage response = await Client.PostAsync("/api/GetLocations", data);

            string str = await response.Content.ReadAsStringAsync();

            var deserializedResponse = JsonConvert.DeserializeObject <ResponseWrapper <GetLocationsResponse, AddressServiceErrorCode> >(str);

            if (deserializedResponse.HasContent && deserializedResponse.IsSuccessful)
            {
                return(deserializedResponse.Content.LocationDetails);
            }
            throw new System.Exception($"Bad response from GetLocations");
        }
Exemplo n.º 12
0
        public IEnumerable <Location> GetLocations(GetLocationsRequest request)
        {
            var locations = _friendlyContext.Locations
                            .Include(l => l.LocationType)
                            .Include(l => l.LocationType.Ratings)
                            .Include(l => l.LocationType.Ratings.Select(x => x.Tag))
                            .Include(l => l.LocationType.Checks)
                            .Include(l => l.LocationType.Checks.Select(x => x.Tag))
                            .Include(l => l.ImageLinks)
                            .ToList();

            if (request != null && request.Latitude.HasValue && request.Longitude.HasValue && request.Radius.HasValue)
            {
                var point = new GeoPoint {
                    Latitude = (double)request.Latitude.Value, Longitude = (double)request.Longitude.Value
                };
                var bounds = _locationBoundsService.GetBoundsForPoint(point, request.Radius.Value);
                locations = locations.Where(l => _locationBoundsService.IsPointInBounds(new GeoPoint {
                    Latitude = (double)l.Latitude, Longitude = (double)l.Longitude
                }, bounds)).ToList();
            }

            return(locations);
        }
Exemplo n.º 13
0
 /// <remarks/>
 public void GetLocationsAsync(GetLocationsRequest Request, object userState) {
     if ((this.GetLocationsOperationCompleted == null)) {
         this.GetLocationsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetLocationsOperationCompleted);
     }
     this.InvokeAsync("GetLocations", new object[] {
                 Request}, this.GetLocationsOperationCompleted, userState);
 }
Exemplo n.º 14
0
 /// <remarks/>
 public void GetLocationsAsync(GetLocationsRequest Request) {
     this.GetLocationsAsync(Request, null);
 }
Exemplo n.º 15
0
 public GetLocationsResult GetLocations(GetLocationsRequest Request) {
     object[] results = this.Invoke("GetLocations", new object[] {
                 Request});
     return ((GetLocationsResult)(results[0]));
 }