public async Task <IActionResult> Get(string name, string address) { var geolocationResults = await _geolocationService.GetCoordinates(address); if (geolocationResults == null || !geolocationResults.Results.Any()) { return(NotFound("Location")); } var geolocation = geolocationResults.Results.First().Geometry.Location; var results = await _ratingsService.GetRatings(name, geolocation.Latitude, geolocation.Longitude); if (results == null || !results.Establishments.Any()) { return(NotFound("Establishment")); } return (Ok(new List <RatingsVm>( results.Establishments.Select( e => new RatingsVm { BusinessName = e.BusinessName, BusinessPostCode = e.PostCode, Rating = e.RatingValue, RatingDate = e.RatingDate, RatingKey = e.RatingKey, HygieneScore = e.Scores?.Hygiene, StructuralScore = e.Scores?.Structural, ManagementScore = e.Scores?.ConfidenceInManagement })))); }
public ActionResult Edit(ActivitiesViewModel model) { if (ModelState.IsValid) { string successMessage = "Activity successfully edited."; string errorMessage = "Unable to edit the activity."; try { // Get co-ordianates of address IGeolocationService geolocationService = UtilityFactory.GetGeolocationService(); Location location = geolocationService.GetCoordinates( String.Format("{0}, {1}, {2}", model.Address, model.PackageCity, model.PackageState.ToString())); Activity activity = new Activity() { ActivityId = model.ActivityId, Name = model.ActivityName, Description = model.Description, Address = model.Address, Status = PackageStatusEnum.Available, PackageId = model.PackageId, Latitude = location.Latitude, Longitude = location.Longitude }; ResultEnum result = activityService.UpdateActivity(activity); if (result == ResultEnum.Success) { model.SuccessMessage = successMessage; } else { model.ErrorMessage = errorMessage; } return(View(model)); } catch { model.ErrorMessage = errorMessage; } } return(View(model)); }
public async Task <IActionResult> Get(string address) { try { var results = await _geolocationService.GetCoordinates(address); if (results == null || !results.Results.Any()) { return(NotFound()); } return(Ok(new GeolocationVm { Address = address, Latitude = results.Results.FirstOrDefault().Geometry.Location.Latitude, Longitude = results.Results.FirstOrDefault().Geometry.Location.Longitude })); } catch (Exception ex) { return(StatusCode(500, ex)); } }