private void SaveTaxCalculationCompletion(string chosenName, string coinType, decimal exchangeRate, byte nrOfDecimals)
 {
     var taxIndicatorModelList = TaxIndicators.ToList().ToCompletedList();
     //multiply with the exchange rate
     taxIndicatorModelList.ForEach(p =>
     {
         if (!string.IsNullOrEmpty(p.Value))
         {
             var valueDec = DecimalConvertor.Instance.StringToDecimal(p.Value);
             p.Value = DecimalConvertor.Instance.DecimalToString(valueDec * exchangeRate, nrOfDecimals);
         }
     }
     );
     CompletedIndicatorDbModel contentModel = new CompletedIndicatorDbModel()
     {
         CompletedIndicators = taxIndicatorModelList,
         PreviousIndicatorId = null
     };
     if (setupModel.Rectifying)
     {
         contentModel.PreviousIndicatorId = setupModel.SelectedTaxCalculation.Id;
     }
     var content = VmUtils.SerializeEntity(contentModel);
     TaxCalculationOtherData otherData = new TaxCalculationOtherData()
     {
         VerifiedBy = setupModel.VerifiedBy,
         CreatedBy = setupModel.CreatedBy,
         CoinType = coinType,
         ExchangeRate = exchangeRate,
         Month = setupModel.Month,
         NrOfDecimals = setupModel.NrOfDecimals,
         Name = chosenName + " - " + coinType,
         Year = setupModel.Year,
         SecondTypeReport = isSecondTypeReport,
         LastModifiedDate = DateTime.Now
     };
     //save the data in the DB
     TaxCalculations tc = new TaxCalculations()
     {
         CompanyId = setupModel.SelectedCompany.Id,
         IndicatorId = setupModel.SelectedIndicatorList.Id,
         Rectifying = setupModel.Rectifying,
         Content = content,
         OtherData = VmUtils.SerializeEntity(otherData)
     };
     taxCalculationRepository.Create(tc);
 }
        public void SetSetupModel(object param)
        {
            try
            {
                selectedTaxCalculationVm = param as TaxCalculationsViewModel;
                var calculation = taxCalculationRepository.Get(selectedTaxCalculationVm.Id);
                var completedIndicatorDbModel = VmUtils.Deserialize<CompletedIndicatorDbModel>(calculation.Content);
                List<CompletedIndicatorVm> savedEntities = completedIndicatorDbModel.CompletedIndicators;
                initialOtherData = VmUtils.Deserialize<TaxCalculationOtherData>(calculation.OtherData);

                DecimalConvertor.Instance.SetNumberOfDecimals(initialOtherData.NrOfDecimals);
                var vmList = savedEntities.ToVmList();
                //load the previous values
                vmList.ForEach(p =>
                {
                    if (p.Type == TaxIndicatorType.Numeric)
                    {
                        p.InitialValueField = p.ValueField;
                        var valueDec = DecimalConvertor.Instance.StringToDecimal(p.ValueField);
                        p.ValueField = DecimalConvertor.Instance.DecimalToString(valueDec * initialOtherData.ExchangeRate, initialOtherData.NrOfDecimals);
                    }
                });
                TaxIndicators = new ObservableCollection<TaxIndicatorViewModel>(vmList);
                ExecuteTaxCalculation(null);

            }
            catch (Exception ex)
            {
                Logger.Instance.Log.Error(ex);
                WindowHelper.OpenErrorDialog(Messages.Error_LoadingData);
            }
        }