예제 #1
0
 private static MapRequest CreateMapRequest(MapRequestAVM mapRequestAVM)
 {
     var mapRequest = new MapRequest(mapRequestAVM.Email, mapRequestAVM.Latitude.Value, mapRequestAVM.Longitude.Value,DateTime.Now);
     using (MediatelModel context = new MediatelModel())
     {
         context.MapRequests.Add(mapRequest);
         context.SaveChanges();
     }
     return mapRequest;
 }
예제 #2
0
 private static MapRequest CreateMapRequest(MapRequestVM mapRequestVM)
 {
     double latitude = MapRequestsHelper.ConvertLatitude(mapRequestVM.LatDegrees, mapRequestVM.LatMinutes, mapRequestVM.LatSeconds, mapRequestVM.LatDirection);
     double longitude = MapRequestsHelper.ConvertLongitude(mapRequestVM.LonDegrees, mapRequestVM.LonMinutes, mapRequestVM.LonSeconds, mapRequestVM.LonDirection);
     var mapRequest = new MapRequest(mapRequestVM.Email, latitude, longitude,DateTime.Now);
     using (MediatelModel context = new MediatelModel())
     {
         context.MapRequests.Add(mapRequest);
         context.SaveChanges();
     }
     return mapRequest;
 }
예제 #3
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;
        }