Ejemplo n.º 1
0
        public static OrderWithStatus FromOrder(Order order)
        {
            // To simulate a real backend process, we fake status updates based on the amount
            // of time since the order was placed
            string        statusText;
            List <Marker> Mapmarkers;
            var           dispatchTime = order.CreatedTime.Add(PreparationDuration);

            if (DateTime.Now < dispatchTime)
            {
                statusText = "Preparing";
                Mapmarkers = new List <Marker>
                {
                    ToMapmarker("You", order.DeliveryLocation, showPopup: true)
                };
            }
            else if (DateTime.Now < dispatchTime + DeliveryDuration)
            {
                statusText = "Out for delivery";

                var startPosition = ComputeStartPosition(order);
                var proportionOfDeliveryCompleted = Math.Min(1, (DateTime.Now - dispatchTime).TotalMilliseconds / DeliveryDuration.TotalMilliseconds);
                var driverPosition = LatLong.Interpolate(startPosition, order.DeliveryLocation, proportionOfDeliveryCompleted);
                Mapmarkers = new List <Marker>
                {
                    ToMapmarker("You", order.DeliveryLocation),
                    ToMapmarker("Driver", driverPosition, showPopup: true),
                };
            }
            else
            {
                statusText = "Delivered";
                Mapmarkers = new List <Marker>
                {
                    ToMapmarker("Delivery location", order.DeliveryLocation, showPopup: true),
                };
            }

            return(new OrderWithStatus
            {
                Order = order,
                StatusText = statusText,
                Mapmarkers = Mapmarkers,
            });
        }
Ejemplo n.º 2
0
 static Marker ToMapmarker(string description, LatLong coords, bool showPopup = false)
 {
     return(new Marker {
         Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup
     });
 }