public ResultadoViewModel(CalculadorPrestamo calculadora) { this.calculadora = calculadora; Fechas = new ObservableCollection <Fecha>(); LoadFechas(calculadora.GetFechas()); }
private async void CalcularResultado() { try { if (string.IsNullOrEmpty(this.monto) || string.IsNullOrEmpty(this.interes) || string.IsNullOrEmpty(this.cuotas)) { IsEnable = false; await dialogService.ShowMessage("Error", "No puede haber campos vacios"); return; } var monto = int.Parse(this.monto); var interes = int.Parse(this.interes); var cuotas = int.Parse(this.cuotas); if (monto <= 0) { IsEnable = false; await dialogService.ShowMessage("Error", "El valor del monto debe ser mayor a cero"); return; } if (interes < 0) { IsEnable = false; await dialogService.ShowMessage("Error", "El valor del interés no puede ser negativo"); return; } if (cuotas <= 0) { IsEnable = false; await dialogService.ShowMessage("Error", "El valor de cuotas debe ser mayor a cero"); return; } // BindablePicker var forma = Formas.ToList().Where(f => f.FormaId == formaElegida).FirstOrDefault(); calculadora = new CalculadorPrestamo { Cuotas = cuotas, Forma = forma, Interes = interes, Monto = monto, }; LoadFechas(calculadora.GetFechas()); MontoTotal = string.Format("Total $ {0}", calculadora.MontoTotal.ToString()); DescripcionCuotas = string.Format("Cuotas {0}", LoadDescripcionCuotas()); FechaFin = string.Format("Termina el {0:dd/MM/yyyy}", Fechas.LastOrDefault().DateTime); Resultado = new ResultadoViewModel(calculadora); IsVisible = true; IsEnable = true; } catch (FormatException) { IsEnable = false; await dialogService.ShowMessage("Error", "Tipo de formato no válido"); return; } catch (Exception ex) { IsEnable = false; await dialogService.ShowMessage("Error", ex.Message); return; } }