Beispiel #1
0
        public ActionResult SaveItinerary(string newItinerary)
        {
            //1. Decode the received JSON string newItinerary to get an Itinerary object.
            //2. Use the result to populate a TripItinerary object as defined by the web service's data contract
            //3. Save the TripItinerary object to the WCF Web Service TripService.

            //Add your code here\
            TripServiceClient client = new TripServiceClient();

            Console.WriteLine(newItinerary);

            //Models.Itinerary itineraryInfo = JsonConvert.DeserializeObject<Models.Itinerary>(newItinerary);

            if (!string.IsNullOrWhiteSpace(newItinerary))
            {
                Models.Itinerary itineraryInfo =
                    JsonConvert.DeserializeObject <Models.Itinerary>(newItinerary);

                TripItinerary trip = new TripItinerary();
                trip.PassengerName = itineraryInfo.PassengerName;
                trip.Date          = itineraryInfo.Date;
                trip.DepartureCity = itineraryInfo.Departure;
                trip.ArrivingCity  = itineraryInfo.Arriving;


                //return the save result received from WCF Web Service TripService to the browser as a JSON string.

                return(Json(client.SaveTripItinerary(trip))); //replace null with the JSON string!!
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
        private void SaveRoute(TripItinerary routeToSave)
        {
            var route = new FavoriteRoute
            {
                FontIconGlyph  = FontIconGlyphs.FilledStar,
                Id             = Guid.NewGuid(),
                IconFontFace   = Constants.SegoeMdl2FontName,
                IconFontSize   = Constants.SymbolFontSize,
                UserChosenName = $"{routeToSave.StartingPlaceName} → {routeToSave.EndingPlaceName}",
            };

            TripLeg startPlace = routeToSave.ItineraryLegs.First();
            TripLeg endPlace   = routeToSave.ItineraryLegs.Last();
            var     places     = new List <SimpleFavoritePlace>();

            places.Add(new SimpleFavoritePlace
            {
                Lat  = startPlace.StartCoords.Latitude,
                Lon  = startPlace.StartCoords.Longitude,
                Name = routeToSave.StartingPlaceName,
                Type = ModelEnums.PlaceType.FavoritePlace
            });
            places.Add(new SimpleFavoritePlace
            {
                Lat  = endPlace.EndCoords.Latitude,
                Lon  = endPlace.EndCoords.Longitude,
                Name = routeToSave.EndingPlaceName,
                Type = ModelEnums.PlaceType.FavoritePlace
            });

            route.RoutePlaces          = places;
            route.RouteGeometryStrings = routeToSave.RouteGeometryStrings.ToList();
            _favoritesService.AddFavorite(route);
        }
        private void TripResultList_ItemClick(object sender, ItemClickEventArgs e)
        {
            TripItinerary model = e.ClickedItem as TripItinerary;

            if (ViewModel.ShowTripDetailsCommand.CanExecute(model))
            {
                ViewModel.ShowTripDetailsCommand.Execute(model);
            }
        }
Beispiel #4
0
 private void CreateNewPlanStrip(TripItinerary thisItinerary)
 {
     TripLegs.Clear();
     loadedGrids.Clear();
     foreach (TripLeg leg in thisItinerary.ItineraryLegs)
     {
         TripLegs.Add(leg);
     }
 }
Beispiel #5
0
    private static TripItinerary MapItineray(itinerariesItinerary arg)
    {
        TripItinerary itin = new TripItinerary();

        itin.PassengerName = arg.passenger;
        itin.DepartureCity = arg.outbound.departure.city;
        itin.ArrivingCity  = arg.outbound.arriving.city;
        itin.Date          = arg.outbound.departure.date.ToString("yyyy-MM-dd");
        return(itin);
    }
Beispiel #6
0
 public ViewPlanDetails(TripItinerary model)
 {
     BackingModel = model;
 }
 public string SaveTripItinerary(TripItinerary itinerary)
 {
     return(DataAccessHelper.SaveItinerary(itinerary));
 }
Beispiel #8
0
    public static string SaveItinerary(TripItinerary newItinerary)
    {
        if (newItinerary == null)
        {
            return("No itinerary received!");
        }

        itinerariesItinerary it = new itinerariesItinerary();

        if (string.IsNullOrWhiteSpace(newItinerary.PassengerName))
        {
            return("Passenger name missing!");
        }

        it.passenger = newItinerary.PassengerName;

        if (!cities.Contains(newItinerary.DepartureCity))
        {
            return("Departure city is not valid!");
        }

        if (!cities.Contains(newItinerary.ArrivingCity))
        {
            return("Arriving city is not valid!");
        }

        it.outbound                = new itinerariesItineraryOutbound();
        it.outbound.departure      = new itinerariesItineraryOutboundDeparture();
        it.outbound.departure.city = newItinerary.DepartureCity;

        it.outbound.arriving      = new itinerariesItineraryOutboundArriving();
        it.outbound.arriving.city = newItinerary.ArrivingCity;;

        if (string.IsNullOrWhiteSpace(newItinerary.Date))
        {
            return("Trip date missing!");
        }

        try {
            it.outbound.departure.date = DateTime.ParseExact(newItinerary.Date, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
            it.outbound.arriving.date  = it.outbound.departure.date;
        }
        catch
        {
            return("Trip date is not a valid date or is in wrong format!");
        }

        string xmlFile = HostingEnvironment.MapPath(@"~/App_Data/itineraries.xml");

        lock (fileLock)
        {
            try
            {
                itineraries allItinearies = null;
                using (FileStream xs = new FileStream(xmlFile, FileMode.Open))
                {
                    XmlSerializer serializor = new XmlSerializer(typeof(itineraries));
                    allItinearies = (itineraries)serializor.Deserialize(xs);
                }
                List <itinerariesItinerary> itineraryList = allItinearies.itinerary.ToList();
                itineraryList.Add(it);

                allItinearies.itinerary = itineraryList.ToArray();

                using (FileStream xs = new FileStream(xmlFile, FileMode.Create))
                {
                    XmlSerializer serializor = new XmlSerializer(typeof(itineraries));
                    serializor.Serialize(xs, allItinearies);
                }
                return("New itineray has been saved.");
            }
            catch (Exception e)
            {
                return("Unable to save new itinerary: " + e.Message);
            }
        }
    }
Beispiel #9
0
        private void ShowTripDetails(TripItinerary model)
        {
            List <Guid> legIds = new List <Guid>();

            for (int i = 0; i <= model.ItineraryLegs.Count - 1; i++)
            {
                legIds.Add(Guid.NewGuid());
            }

            SelectedDetailLegs = model.ItineraryLegs
                                 .Zip(legIds, (x, id) => { x.TemporaryId = id; return(x); })
                                 .ToList();

            ColoredMapLines.Clear();
            int legIndex = 0;

            foreach (TripLeg leg in model.ItineraryLegs)
            {
                List <ColoredMapLinePoint> coloredPoints = GooglePolineDecoder.Decode(leg.LegGeometryString)
                                                           .Select(x =>
                {
                    if (leg.Mode == ApiEnums.ApiMode.Walk)
                    {
                        return(new ColoredMapLinePoint(x, HslColors.GetModeColor(leg.Mode), true));
                    }
                    else
                    {
                        return(new ColoredMapLinePoint(x, HslColors.GetModeColor(leg.Mode)));
                    }
                })
                                                           .ToList();

                // Add one extra point at the beginning if this is a walk leg to account for legs starting too far away
                if (leg.Mode == ApiEnums.ApiMode.Walk && legIndex > 0)
                {
                    BasicGeoposition?previousLegLastPoint = ColoredMapLines.LastOrDefault()?.LastOrDefault()?.Coordinates;
                    if (previousLegLastPoint != null)
                    {
                        coloredPoints.Insert(0, new ColoredMapLinePoint(previousLegLastPoint.Value, HslColors.GetModeColor(ApiEnums.ApiMode.Walk), true));
                    }
                }

                // Add one extra point at the end to account for legs ending too early
                coloredPoints.Add(new ColoredMapLinePoint(leg.EndCoords, HslColors.GetModeColor(leg.Mode), leg.Mode == ApiEnums.ApiMode.Walk));
                var mapLine = new ColoredMapLine(coloredPoints, legIds[legIndex]);
                ColoredMapLines.Add(mapLine);
                legIndex++;
            }

            var stops = new List <IMapPoi>();

            stops.AddRange(model.ItineraryLegs.Zip(legIds, (x, id) => {
                IMapPoi poi = x.StartPlaceToPoi();
                poi.Id      = id;
                return(poi);
            }));
            IMapPoi endPoi = model.ItineraryLegs.Last().EndPlaceToPoi();

            endPoi.Id = legIds.Last();
            stops.Add(endPoi);

            MapStops = stops;

            _messengerService.Send(new MessageTypes.ViewPlanDetails(model));
            IsInDetailedState = true;
        }