public async Task <IActionResult> GetByAddressAsync([FromQuery] RealEstateApi realEstateApi) { realEstateApi = NormalizeRealEstateApi(realEstateApi); var response = await dbHandler.GetRealEsatesByAddressAsync(realEstateApi); return(HandleResponse(response)); }
public async Task <ResponseObject> GetFromServiceByAddressAsync(RealEstateApi realEstateApi) { string uri = string.Format("https://www.tinglysning.dk/tinglysning/ssl/ejendom/adresse?etage={0}&husnummer={1}&postnummer={2}&sidedoer={3}&vejnavn={4}", realEstateApi.FloorIdentifier, realEstateApi.StreetBuildingIdentifier, realEstateApi.PostCodeIdentifier, realEstateApi.SuiteIdentifier, realEstateApi.StreetName); return(await HandleResponseAsync(uri)); }
private RealEstateApi NormalizeRealEstateApi(RealEstateApi realEstateApi) { return(new RealEstateApi() { FloorIdentifier = realEstateApi.FloorIdentifier?.ToUpper(), StreetBuildingIdentifier = realEstateApi.StreetBuildingIdentifier?.ToUpper(), PostCodeIdentifier = realEstateApi.PostCodeIdentifier, SuiteIdentifier = realEstateApi.SuiteIdentifier?.ToUpper(), StreetName = realEstateApi.StreetName?.ToTitleCase() }); }
public async Task <ResponseObject> GetRealEsatesByAddressAsync(RealEstateApi realEstateApi) { /* * Query realEstateQuery = collection * .WhereEqualTo("streetName", realEstateApi.StreetName) * .WhereEqualTo("postCodeIdentifier", realEstateApi.PostCodeIdentifier); */ Query realEstateQuery = collection .WhereEqualTo("streetName", realEstateApi.StreetName) .WhereEqualTo("floorIdentifier", realEstateApi.FloorIdentifier) .WhereEqualTo("streetBuildingIdentifier", realEstateApi.StreetBuildingIdentifier) .WhereEqualTo("suiteIdentifier", realEstateApi.SuiteIdentifier) .WhereEqualTo("postCodeIdentifier", realEstateApi.PostCodeIdentifier); QuerySnapshot realEstatesSnapshot = await realEstateQuery.GetSnapshotAsync(); if (realEstatesSnapshot.Count > 0) { var selectedRealEstates = new List <RealEstate>(); foreach (var item in realEstatesSnapshot.Documents) { RealEstate realEstate = item.ConvertTo <RealEstate>(); /* * if (realEstate != null && realEstateApi.StreetBuildingIdentifier != null && realEstate.StreetBuildingIdentifier.ToLower().Contains(realEstateApi.StreetBuildingIdentifier.ToLower())) * { * selectedRealEstates.Add(realEstate); * }*/ if (realEstate != null) { selectedRealEstates.Add(realEstate); } } if (selectedRealEstates.Count > 0) { return(new ResponseObject { ResponseStatus = ResponseStatus.OK, Content = JsonConvert.SerializeObject(selectedRealEstates) }); } } return(await GetFromServiceByAddressAsync(realEstateApi)); }