public static IList<MapSearchRequestHistoryVM> GetMapSearchRequestsHistory(Func<MapRequest,object> orderBy = null)
 {
     IList<MapSearchRequestHistoryVM> result = new List<MapSearchRequestHistoryVM>();
     using (MediatelModel context = new MediatelModel())
     {
         IList<MapRequest> mapRequests = null;
         if (orderBy == null)
         {
             mapRequests = context.MapRequests.Include("MapSearchResult").OrderBy(m => m.DateCreated).ToList();
             mapRequests = mapRequests.Reverse().ToList();
         }
         else
         {
             mapRequests = context.MapRequests.Include("MapSearchResult").OrderBy(orderBy).ToList();
         }
         foreach (MapRequest mapRequest in mapRequests)
         {
             var mapSerReqHis = new MapSearchRequestHistoryVM();
             mapSerReqHis.ResultCode = mapRequest.MapSearchResult.ResultCode;
             mapSerReqHis.City = mapRequest.MapSearchResult.City;
             mapSerReqHis.Country = mapRequest.MapSearchResult.Country;
             mapSerReqHis.DateCreated = mapRequest.DateCreated;
             mapSerReqHis.Email = mapRequest.Email;
             mapSerReqHis.HouseNumber = mapRequest.MapSearchResult.HouseNumber;
             mapSerReqHis.Latitude = mapRequest.Latitude;
             mapSerReqHis.Longitude = mapRequest.Longitude;
             mapSerReqHis.PostCode = mapRequest.MapSearchResult.PostCode;
             result.Add(mapSerReqHis);
         }
     }
     return result;
 }
 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;
 }
 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;
 }
 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;
 }