Exemple #1
0
        async void Convert()
        {
            if (string.IsNullOrEmpty(Amount))
            {
                await dialogService.ShowMessage(
                    Lenguages.Error,
                    Lenguages.AmountNumericValidation);

                return;
            }

            decimal amount = 0;

            if (!decimal.TryParse(Amount, out amount))
            {
                await dialogService.ShowMessage(
                    Lenguages.Error,
                    Lenguages.AmountNumericValidation);

                return;
            }

            if (string.IsNullOrEmpty(SourceRate))
            {
                await dialogService.ShowMessage(
                    Lenguages.Error,
                    Lenguages.SourceRateValidation);

                return;
            }

            if (string.IsNullOrEmpty(TargetRate))
            {
                await dialogService.ShowMessage(
                    Lenguages.Error,
                    Lenguages.TargetRateValidation);

                return;
            }

            var sourceRate = RateService.GetRateByName(SourceRate);
            var targetRate = RateService.GetRateByName(TargetRate);

            if (sourceRate == null || targetRate == null)
            {
                await dialogService.ShowMessage(
                    Lenguages.Error,
                    "Rate not found");

                return;
            }

            var amountConverted = amount /
                                  (decimal)sourceRate.TaxtRate *
                                  (decimal)targetRate.TaxtRate;

            Result = string.Format("{0} {1:C2} = {2} {3:C2}",
                                   sourceRate.Code,
                                   Amount,
                                   targetRate.Code,
                                   amountConverted);
        }