public async Task <IHttpActionResult> CreateTrip(TripReadModel model) { var waypoints = model.WayPoints.Select(w => w.Place).ToList(); waypoints.Insert(0, model.StartPoint); waypoints.Add(model.EndPoint); DistanseMatrixResponseModel distanseMatrixModel = await _distanceMatrixQuery.GetDistanceMatrix(waypoints); if (!distanseMatrixModel.Validate()) { throw new ApplicationException("Invalid response from distanse matrix API"); } double[,] matrix = distanseMatrixModel.ToArray(); var route = _routeService.CalculateRoute(matrix, 0, waypoints.Count - 1, model.Algorithm); var trip = model.ToEntity(); _context.Trips.Add(trip); await _context.SaveChangesAsync(); return(Ok(route)); }
public async Task <ExternalRouteModel> Index(string fromName, string toName, int filter, float weight, string parcelType) { if (weight >= RouteMetrics.MaxWeight || _blackList.Contains(parcelType)) { return(new ExternalRouteModel { Duration = 0, Price = 0, Valid = false }); } var path = await _routeService.CalculateRoute(fromName, toName, parcelType, weight, false, (FilterType)filter); return(new ExternalRouteModel { Price = (decimal)(path?.TotalPrice ?? 0), Duration = path?.TotalDuration ?? 0, Valid = path?.Segments?.Length > 0 }); }