public async Task <IActionResult> GetRoute(Guid id) { if (id == Guid.Empty) { return(NotFound()); } var userId = _userManager.GetUserId(User); var route = await _unitOfWork.RoutePlanner.GetRouteById(id, userId); var dto = new RouteItemDto() { Origin = new CoordinatesDto() { Latitude = route.OriginLatitude, Longitude = route.OriginLongitude }, Destination = new CoordinatesDto() { Latitude = route.DestinationLatitude, Longitude = route.DestinationLongitude, }, Polyline = route.Polyline, Name = route.Name }; dto.Waypoints = JsonConvert.DeserializeObject <CoordinatesDto[]>(route.Waypoints); return(Ok(dto)); }
public IActionResult CreateRoute([FromBody] RouteItemDto route) { if (!ModelState.IsValid) { return(NotFound()); } string jsonWaypoints = null; if (route.Waypoints != null) { jsonWaypoints = JsonConvert.SerializeObject(route.Waypoints); } var userId = _userManager.GetUserId(User); var model = new RouteItem() { OriginLatitude = route.Origin.Latitude, OriginLongitude = route.Origin.Longitude, DestinationLatitude = route.Destination.Latitude, DestinationLongitude = route.Destination.Longitude, Waypoints = jsonWaypoints, UserId = userId, Name = route.Name, Polyline = route.Polyline, ParentId = route.Parent }; _unitOfWork.RoutePlanner.AddRoute(model); _unitOfWork.Complete(); var nodeDto = _mapper.Map <NodeDto>(model); var dto = new { route = route, node = nodeDto }; return(Ok(dto)); }