public ResponseMessage <List <RecyclingBank> > GetAllClose(RecyclingBankRequest _recyclingBankRequest) { ResponseMessage <List <RecyclingBank> > response = new ResponseMessage <List <RecyclingBank> >(); try { List <RecyclingBank> banks = _recyclingBankRepository.GetAll(); var currentLocation = new GeoCoordinatePortable.GeoCoordinate(double.Parse(_recyclingBankRequest.Coordinate.Split(',')[0], CultureInfo.InvariantCulture), double.Parse(_recyclingBankRequest.Coordinate.Split(',')[1], CultureInfo.InvariantCulture)); foreach (var item in banks) { var bankLocation = new GeoCoordinatePortable.GeoCoordinate(double.Parse(item.Position.Split(',')[0], CultureInfo.InvariantCulture), double.Parse(item.Position.Split(',')[1], CultureInfo.InvariantCulture)); if (currentLocation.GetDistanceTo(bankLocation) < (_recyclingBankRequest.Radius * 1000)) { response.ResponseObject.Add(item); } } response.IsSuccess = true; response.ErrorMessage = "Success"; } catch (Exception ex) { response.IsSuccess = false; response.ErrorMessage = ex.Message; } return(response); }
public List <RecyclingBank> GetAllClose([FromBody] RecyclingBankRequest recyclingBankRequest) { ResponseMessage <List <RecyclingBank> > request = _recyclingBankService.GetAllClose(recyclingBankRequest); if (request == null || !request.IsSuccess || request.ResponseObject == null) { throw new Exception(request.ErrorMessage); } return(request.ResponseObject); }