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;
            bool          isDelivered = false;
            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";
                isDelivered = true;
                mapMarkers  = new List <Marker>
                {
                    ToMapMarker("Delivery location", order.DeliveryLocation, showPopup: true),
                };
            }

            return(new OrderWithStatus
            {
                Order = order,
                StatusText = statusText,
                IsDelivered = isDelivered,
                MapMarkers = mapMarkers,
            });
        }
Example #2
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.AddSeconds(10);
            var           deliveryDuration = TimeSpan.FromMinutes(1); // Unrealistic, but more interesting to watch

            if (DateTime.Now < dispatchTime)
            {
                statusText = "Recogiendo el pedido";
                mapMarkers = new List <Marker>
                {
                    ToMapMarker("Lugar de recogida", order.DeliveryLocation, showPopup: true)
                };
            }
            else if (DateTime.Now < dispatchTime + deliveryDuration)
            {
                statusText = "Realizando el envio";

                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("Lugar de entrega", order.DeliveryLocation),
                    ToMapMarker("Mensajero", driverPosition, showPopup: true),
                };
            }
            else
            {
                statusText = "Terminado";
                mapMarkers = new List <Marker>
                {
                    ToMapMarker("Lugar de entrega", order.DeliveryLocation, showPopup: true),
                };
            }

            return(new OrderWithStatus
            {
                Order = order,
                StatusText = statusText,
                MapMarkers = mapMarkers,
            });
        }
Example #3
0
 static Marker ToMapMarker(string description, LatLong coords, bool showPopup = false)
 => new Marker
 {
     Description = description, X = coords.Longitude, Y = coords.Latitude, ShowPopup = showPopup
 };