private async Task ValidateLocation(Location newLocation) { CoordServiceResult coordResult = await _coordService.Lookup(newLocation.Name); if (!coordResult.Success) { throw new UseCaseException(HttpStatusCode.BadRequest, coordResult.Message); } newLocation.Longitude = coordResult.Longitude; newLocation.Latitude = coordResult.Latitude; }
private async Task ValidateLocations(IEnumerable <Location> locations) { foreach (var location in locations) { var coordResult = await _coordService.Lookup(location.Name); if (!coordResult.Success) { throw new UseCaseException(HttpStatusCode.BadRequest, coordResult.Message); } location.Longitude = coordResult.Longitude; location.Latitude = coordResult.Latitude; } }
public async Task <JsonResult> Post(string tripName, [FromBody] StopViewModel vm) { try { if (ModelState.IsValid) { var newStop = Mapper.Map <Stop>(vm); var coordResult = await _coordService.Lookup(vm.Name); if (!coordResult.Success) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json($"Error adding stop with name {vm.Name}, {coordResult.Message}")); } newStop.Longitude = coordResult.Longitude; newStop.Latitude = coordResult.Latitude; _worldRepository.AddStop(tripName, newStop); if (_worldRepository.SaveAll()) { Response.StatusCode = (int)HttpStatusCode.Created; return(Json(Mapper.Map <StopViewModel>(newStop))); } } } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json($"Error adding stop with name {vm.Name}")); } Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(new { Message = "Failed", ModelState = ModelState })); }