Пример #1
0
        public async Task <ResponseObject> GetHousingCooperativesByAddressAsync(HousingCooperativeApi housingCooperativeApi)
        {
            Query housingCooperativesQuery = collection
                                             .WhereEqualTo("streetName", housingCooperativeApi.StreetName)
                                             .WhereEqualTo("streetBuildingIdentifier", housingCooperativeApi.StreetBuildingIdentifier)
                                             .WhereEqualTo("postCodeIdentifier", housingCooperativeApi.PostCodeIdentifier)
                                             .WhereEqualTo("floorIdentifier", housingCooperativeApi.FloorIdentifier)
                                             .WhereEqualTo("suiteIdentifier", housingCooperativeApi.SuiteIdentifier);

            QuerySnapshot housingCooperativesSnapshot = await housingCooperativesQuery.GetSnapshotAsync();

            if (housingCooperativesSnapshot.Count > 0)
            {
                var selectedHousingCooperatives = new List <HousingCooperative>();

                foreach (var item in housingCooperativesSnapshot.Documents)
                {
                    var housingCooperative = item.ConvertTo <HousingCooperative>();
                    if (housingCooperative != null)
                    {
                        selectedHousingCooperatives.Add(housingCooperative);
                    }
                }
                if (selectedHousingCooperatives.Count > 0)
                {
                    return(new ResponseObject
                    {
                        ResponseStatus = ResponseStatus.OK,
                        Content = JsonConvert.SerializeObject(selectedHousingCooperatives)
                    });
                }
            }
            return(await GetFromServiceByAddressAsync(housingCooperativeApi));
        }
Пример #2
0
        public async Task <IActionResult> GetByMunicipalityAndStreetCodesAsync([FromQuery] HousingCooperativeApi housingCooperativeApi)
        {
            housingCooperativeApi = NormalizeHousingCooperativeApi(housingCooperativeApi);

            var response = await dbHandler.GetHousingCooperativesByMunicipalityAndStreetCodesAsync(housingCooperativeApi);

            return(HandleResponse(response));
        }
Пример #3
0
        public async Task <ResponseObject> GetFromServiceByAddressAsync(HousingCooperativeApi housingCooperativeApi)
        {
            string uri = string.Format("https://www.tinglysning.dk/tinglysning/ssl/andelsbolig/postnummervej?etage={0}&husnummer={1}&postnummer={2}&sidedoer={3}&vejnavn={4}",
                                       housingCooperativeApi.FloorIdentifier,
                                       housingCooperativeApi.StreetBuildingIdentifier,
                                       housingCooperativeApi.PostCodeIdentifier,
                                       housingCooperativeApi.SuiteIdentifier,
                                       housingCooperativeApi.StreetName);

            return(await HandleResponseAsync(uri));
        }
Пример #4
0
 private HousingCooperativeApi NormalizeHousingCooperativeApi(HousingCooperativeApi housingCooperativeApi)
 {
     return(new HousingCooperativeApi()
     {
         FloorIdentifier = housingCooperativeApi.FloorIdentifier?.ToUpper(),
         StreetBuildingIdentifier = housingCooperativeApi.StreetBuildingIdentifier?.ToUpper(),
         PostCodeIdentifier = housingCooperativeApi.PostCodeIdentifier,
         SuiteIdentifier = housingCooperativeApi.SuiteIdentifier?.ToUpper(),
         StreetName = housingCooperativeApi.StreetName?.ToTitleCase(),
         MunicipalityCode = housingCooperativeApi.MunicipalityCode,
         StreetCode = housingCooperativeApi.StreetCode
     });
 }
Пример #5
0
        public async Task <ResponseObject> GetHousingCooperativesByMunicipalityAndStreetCodesAsync(HousingCooperativeApi housingCooperativeApi)
        {
            if (!int.TryParse(housingCooperativeApi.MunicipalityCode, out int municipalityCode))
            {
                return(new ResponseObject
                {
                    ResponseStatus = ResponseStatus.BAD_REQUEST,
                    Content = "Wrong municipality code input"
                });
            }
            Query housingCooperativesQuery = collection
                                             .WhereEqualTo("streetCode", housingCooperativeApi.StreetCode)
                                             .WhereEqualTo("streetBuildingIdentifier", housingCooperativeApi.StreetBuildingIdentifier)
                                             .WhereEqualTo("municipalityCode", municipalityCode.ToString("D4"))
                                             .WhereEqualTo("floorIdentifier", housingCooperativeApi.FloorIdentifier)
                                             .WhereEqualTo("suiteIdentifier", housingCooperativeApi.SuiteIdentifier);

            QuerySnapshot housingCooperativesSnapshot = await housingCooperativesQuery.GetSnapshotAsync();

            if (housingCooperativesSnapshot.Count > 0)
            {
                var selectedHousingCooperatives = new List <HousingCooperative>();

                foreach (var item in housingCooperativesSnapshot.Documents)
                {
                    var housingCooperative = item.ConvertTo <HousingCooperative>();
                    if (housingCooperative != null)
                    {
                        selectedHousingCooperatives.Add(housingCooperative);
                    }
                }
                if (selectedHousingCooperatives.Count > 0)
                {
                    return(new ResponseObject
                    {
                        ResponseStatus = ResponseStatus.OK,
                        Content = JsonConvert.SerializeObject(selectedHousingCooperatives)
                    });
                }
            }
            return(await GetFromServiceByMunicipalityAndStreetCodesAsync(housingCooperativeApi));
        }
Пример #6
0
        public async Task <ResponseObject> GetFromServiceByMunicipalityAndStreetCodesAsync(HousingCooperativeApi housingCooperativeApi)
        {
            string uri = string.Format("https://www.tinglysning.dk/tinglysning/ssl/andelsbolig/kommunevej?etage={0}&husnummer={1}&kommunekode={2}&sidedoer={3}&vejkode={4}",
                                       housingCooperativeApi.FloorIdentifier,
                                       housingCooperativeApi.StreetBuildingIdentifier,
                                       housingCooperativeApi.MunicipalityCode,
                                       housingCooperativeApi.SuiteIdentifier,
                                       housingCooperativeApi.StreetCode);

            return(await HandleResponseAsync(uri));
        }