예제 #1
0
        private static MapSearchResultVM SearchForAddress(MapRequest mapRequest)
        {
            string cacheKey = String.Format("{0};{1}", mapRequest.Latitude, mapRequest.Longitude);

            OSMClient.OSMReverseResponse mapSearchResponse;
            object cachedObject = HttpContext.Current.Cache.Get(cacheKey);

            if (cachedObject != null)
            {
                mapSearchResponse = cachedObject as OSMClient.OSMReverseResponse;
            }
            else
            {
                mapSearchResponse = OSMClient.SearchForAddressOSM(mapRequest.Latitude, mapRequest.Longitude);
                // TODO better cache configuration based on statistics of searches
                HttpContext.Current.Cache.Add(cacheKey, mapSearchResponse, null, DateTime.Now.AddDays(1), TimeSpan.Zero, CacheItemPriority.Default, null);
            }
            MapSearchResultVM mapSearchResultVM = new MapSearchResultVM();

            mapSearchResultVM.ResultCode = mapSearchResponse.ResultCode.ToString();
            if (mapSearchResponse.ResultCode == OSMClient.SearchResultCode.OK)
            {
                mapSearchResultVM.City        = mapSearchResponse.Address.City;
                mapSearchResultVM.Country     = mapSearchResponse.Address.Country;
                mapSearchResultVM.HouseNumber = mapSearchResponse.Address.HouseNumber;
                mapSearchResultVM.PostCode    = mapSearchResponse.Address.PostCode;
            }
            CreateMapSearchResult(mapSearchResultVM, mapRequest.MapRequestId);
            return(mapSearchResultVM);
        }
예제 #2
0
 public PartialViewResult SearchAddress(MapRequestVM mapRequest)
 {
     try
     {
         MapSearchResultVM mapSearchResult = MapRequests.SearchForAddress(mapRequest);
         return(PartialView(mapSearchResult));
     }
     catch (ValidationException e)
     {
         return(PartialView("ValidationException", e));
     }
 }
예제 #3
0
        private static MapSearchResult CreateMapSearchResult(MapSearchResultVM mapSearchResultVM, int mapRequestId)
        {
            MapSearchResult mapSearchResult = new MapSearchResult();

            mapSearchResult.City         = mapSearchResultVM.City;
            mapSearchResult.Country      = mapSearchResultVM.Country;
            mapSearchResult.DateCreate   = DateTime.Now;
            mapSearchResult.HouseNumber  = mapSearchResultVM.HouseNumber;
            mapSearchResult.MapRequestId = mapRequestId;
            mapSearchResult.PostCode     = mapSearchResultVM.PostCode;
            mapSearchResult.ResultCode   = mapSearchResultVM.ResultCode;
            using (MediatelModel context = new MediatelModel())
            {
                context.MapSearchResults.Add(mapSearchResult);
                context.SaveChanges();
            }
            return(mapSearchResult);
        }