public async Task <ActionResult> Index(POIBrowseModel filter) { if (filter?.ReferenceData == null) { if (filter == null) { filter = new POIBrowseModel(); filter.ShowAdvancedOptions = true; } filter.ReferenceData = await GetCoreReferenceDataAsync(); } var cpManager = new API.Common.POIManager(); //dropdown selections of -1 represent an intended null selection, fix this by nulling relevant items filter.CountryIDs = this.ConvertNullableSelection(filter.CountryIDs); filter.LevelIDs = this.ConvertNullableSelection(filter.LevelIDs); filter.ConnectionTypeIDs = this.ConvertNullableSelection(filter.ConnectionTypeIDs); filter.OperatorIDs = this.ConvertNullableSelection(filter.OperatorIDs); filter.StatusTypeIDs = this.ConvertNullableSelection(filter.StatusTypeIDs); filter.UsageTypeIDs = this.ConvertNullableSelection(filter.UsageTypeIDs); filter.DataProviderIDs = this.ConvertNullableSelection(filter.DataProviderIDs); filter.IncludeComments = true; if (IsRequestByRobot) { //force mirror db when browser is a robot filter.AllowMirrorDB = true; filter.AllowDataStoreDB = false; } if (!String.IsNullOrWhiteSpace(filter.Country)) { //TODO: cache country id lookup using (var refData = new OCM.API.Common.ReferenceDataManager()) { var countrySelected = refData.GetCountryByName(filter.Country); if (countrySelected != null) { filter.CountryIDs = new int[] { countrySelected.ID }; } } } else { //default to UK // if (filter.CountryIDs == null) filter.CountryIDs = new int[] { 1 }; } filter.MaxResults = 100; if (!String.IsNullOrWhiteSpace(filter.SearchLocation)) { if (filter.SearchLocation.ToUpper().StartsWith("OCM-")) { filter.SearchLocation = filter.SearchLocation.Replace("OCM-", ""); } if (filter.SearchLocation.ToUpper().StartsWith("OCM")) { filter.SearchLocation = filter.SearchLocation.Replace("OCM", ""); } if (IsNumeric(filter.SearchLocation.Trim())) { int poiID = -1; //treat numbers as OCM ref if (int.TryParse(filter.SearchLocation.Trim(), out poiID)) { filter.ChargePointIDs = new int[] { poiID }; } } else { //attempt to geocode var geocode = new GeocodingHelper(_settings); string searchCountryName = null; if (filter.CountryIDs != null && filter.CountryIDs.Count() > 0) { var searchCountry = filter.ReferenceData.Countries.FirstOrDefault(c => c.ID == filter.CountryIDs[0]); searchCountryName = searchCountry.Title; } API.Common.Model.Extended.GeocodingResult position = null; // FIXME: geocoding is disabled, find an laternative service to use //geocode.GeolocateAddressInfo_Google(filter.SearchLocation.Trim() + (searchCountryName != null ? ", " + searchCountryName : "")); if (filter.SearchLocation.Contains(",")) { var vals = filter.SearchLocation.Split(','); if (IsNumeric(vals[0]) && IsNumeric(vals[1])) { position = new API.Common.Model.Extended.GeocodingResult { Latitude = double.Parse(vals[0]), Longitude = double.Parse(vals[1]) }; } } if (position != null) { filter.Latitude = position.Latitude; filter.Longitude = position.Longitude; if (filter.Distance == null) { filter.Distance = 50; } filter.DistanceUnit = API.Common.Model.DistanceUnit.Miles; //TODO: distance unit KM //if (distanceunit == "km") searchfilters.DistanceUnit = API.Common.Model.DistanceUnit.KM; ViewBag.FormattedAddress = position.Address ?? ""; } } } filter.POIList = (await cpManager.GetPOIListAsync((OCM.API.Common.APIRequestParams)filter, filter.ReferenceData)).ToList(); return(View(filter)); }
// GET: /POI/Details/5 //[OutputCache(Duration=240, VaryByParam="id")] public async Task <ActionResult> Details(int id = 0, string layout = null, string status = null) { if (id <= 0) { return(RedirectToAction("Index")); } if (status != null) { ViewBag.Status = status; } OCM.API.Common.POIManager cpManager = new API.Common.POIManager(); POIViewModel viewModel = new POIViewModel(); var poi = await cpManager.Get(id, true, allowDiskCache : false, allowMirrorDB : true); if (poi != null) { ViewBag.FullTitle = "Location Details: OCM-" + poi.ID + " " + poi.AddressInfo.Title; List <LocationImage> imageList = null; // new OCM.MVC.App_Code.GeocodingHelper().GetGeneralLocationImages((double)poi.AddressInfo.Latitude, (double)poi.AddressInfo.Longitude); if (imageList != null) { imageList = imageList.Where(i => i.Width >= 500).ToList(); ViewBag.ImageList = imageList.ToList(); } viewModel.POI = poi; if (!IsRequestByRobot) { viewModel.NewComment = new UserComment() { ChargePointID = poi.ID, CommentType = new UserCommentType { ID = 10 }, CheckinStatusType = new CheckinStatusType { ID = 0 } }; System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); viewModel.POIListNearby = (await cpManager.GetPOIListAsync(new APIRequestParams { MaxResults = 10, Latitude = poi.AddressInfo.Latitude, Longitude = poi.AddressInfo.Longitude, Distance = 15, DistanceUnit = DistanceUnit.Miles, AllowMirrorDB = true })).ToList(); viewModel.POIListNearby.RemoveAll(p => p.ID == poi.ID); //don't include the current item in nearby POI list sw.Stop(); System.Diagnostics.Debug.WriteLine(sw.ElapsedMilliseconds); ViewBag.ReferenceData = new POIBrowseModel(await GetCoreReferenceDataAsync()); //get data quality report //if (IsUserAdmin) //{ viewModel.DataQualityReport = new DataAnalysisManager().GetDataQualityReport(poi); //} ViewBag.UserCanEditPOI = false; if (IsUserSignedIn) { var user = new UserManager().GetUser((int)UserID); if (POIManager.CanUserEditPOI(poi, user)) { ViewBag.UserCanEditPOI = true; } } } else { viewModel.POIListNearby = new List <ChargePoint>(); } } return(View(viewModel)); }