Пример #1
0
        public KilometerPerHour CalculateKilometersPerHour(Distance distance, DateTime time)
        {
            if (distance == null) return new KilometerPerHour(0.0);

            var timeForCalculation = time.TimeOfDay.TotalSeconds;
            var distanceForCalculation = distance.GetTotalMeters();

            var sum =  Math.Round((distanceForCalculation/timeForCalculation)*3.6, 2);
            return sum <= 0 ? new KilometerPerHour(0.0) : new KilometerPerHour(sum);
        }
        public void CalculateRunTime()
        {
            _calculator = new Calculator.Calculator();

            var distance = new Distance(SelectedKilometer.Title, SelectedMeter.Title, SelectedCentimeter.Title);
            var date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, SelectedHour.Title,
                                    SelectedMinute.Title, SelectedSecond.Title);

            var kmh = _calculator.CalculateKilometersPerHour(distance, date);
            var minKm = _calculator.CalculateMinutePerKilometer(kmh);
            if (kmh.Value <= 0.0 || minKm.Minutes <= 0) return;

            // Navigate to result page --- publish result message
            _navigationService.NavigateToViewModel<ResultItemDetailViewModel>();
            _eventAggregator.Publish(new ResultMessage {Distance = distance, Date = date, KilometerPerHour = kmh, MinutePerKilometer = minKm});
        }