public void Edit(TaxCalculations entity) { lock (syncObj) { //using (var context = GetContext()) //{ // var existingIndicator = context.TaxCalculations.FirstOrDefault(p => p.Id == entity.Id); // if (existingIndicator == null) // { // throw new Exception("invalid Indicator id: " + entity.Id); // } // else // { // //get companies with the same name but different id // var existingEntity = context.TaxCalculations.FirstOrDefault(p => p.Name == entity.Name && p.Id != entity.Id); // if (existingEntity != null) // { // throw new DuplicateEntityNameException(); // } // SetAllIndicatorsDefaultValue(context, entity); // existingIndicator.Name = entity.Name; // existingIndicator.Content = entity.Content; // existingIndicator.IsDefault = entity.IsDefault; // existingIndicator.CreatedTimestamp = entity.CreatedTimestamp; // base.Commit(context); // } //} } }
//private static void SetAllIndicatorsDefaultValue(TaxCalculatorModelContainer context, TaxCalculations entity) //{ // if (entity.IsDefault) // { // var allIntems = context.TaxCalculations.ToList(); // //set everything as notDefault // allIntems.ForEach(p => p.IsDefault = false); // } //} public void Create(TaxCalculations entity) { lock (syncObj) { try { using (var context = GetContext()) { //SetAllIndicatorsDefaultValue(context, entity); //TaxCalculations soc = new TaxCalculations() //{ // Id = DbIdHelper.GetNextID(), //};] entity.Id = DbIdHelper.GetNextID(); context.TaxCalculations.AddObject(entity); base.Commit(context); } } catch { throw; } } }
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 { SetupModel = param as TaxCalculationSetupModel; ExchangeRateVisibility = SetupModel.CoinType == "LEI" ? Visibility.Collapsed : Visibility.Visible; nrDecimals = setupModel.NrOfDecimals; DecimalConvertor.Instance.SetNumberOfDecimals(nrDecimals); Rectifying = setupModel.Rectifying ? Visibility.Visible : Visibility.Collapsed; //setupModel.Rectifying = false; if (setupModel.Rectifying) { //load the old nr of decimals //load the selected calculation var selectedTaxCalculation = taxCalculationRepository.Get(setupModel.SelectedTaxCalculation.Id); var otherData = VmUtils.Deserialize<TaxCalculationOtherData>(selectedTaxCalculation.OtherData); nrDecimals = (byte)otherData.NrOfDecimals; DecimalConvertor.Instance.SetNumberOfDecimals(nrDecimals); var completeIndicatorDbModel = VmUtils.Deserialize<CompletedIndicatorDbModel>(selectedTaxCalculation.Content); List<CompletedIndicatorVm> completedIndicatorList = completeIndicatorDbModel.CompletedIndicators; var vmList = completedIndicatorList.ToVmList(); //load the previous values vmList.ForEach(p => { if (p.Type == TaxIndicatorType.Numeric) { //var initValue = DecimalConvertor.Instance.DecimalToString(DecimalConvertor.Instance.StringToDecimal(p.ValueField)); //initValue = initValue.Replace(".", string.Empty); //p.InitialValueField = initValue; p.InitialValueField = p.ValueField; //p.ValueField = p.ValueField; } else if (p.Type == TaxIndicatorType.Calculat) { //var initValue = DecimalConvertor.Instance.DecimalToString(DecimalConvertor.Instance.StringToDecimal(p.ValueField)); //initValue = initValue.Replace(".", string.Empty); //p.InitialValueField = initValue; p.InitialValueField = p.ValueField; //p.ValueField = p.ValueField; } }); TaxIndicators = new ObservableCollection<TaxIndicatorViewModel>(vmList); //load the formulas from the indicators var selectedIndicator = indicatorRepository.Get(selectedTaxCalculation.IndicatorId); var dbIndicators = VmUtils.Deserialize<List<TaxIndicator>>(selectedIndicator.Content); if (dbIndicators.Count != TaxIndicators.Count) { WindowHelper.OpenErrorDialog(Messages.Error_FormulaModifiedForRectification); } else { foreach (var indicator in dbIndicators) { //if (indicator.NrCrt != null) { //var existingVmIndicator = TaxIndicators.FirstOrDefault(p => p.NrCrt == indicator.NrCrt); var existingVmIndicator = TaxIndicators[dbIndicators.IndexOf(indicator)]; existingVmIndicator.IndicatorFormula = indicator.IndicatorFormula; existingVmIndicator.TypeDescription = indicator.TypeDescription; existingVmIndicator.Type = VmUtils.GetIndicatorType(indicator.TypeDescription); existingVmIndicator.Style = VmUtils.GetStyleInfo(VmUtils.GetIndicatorType(indicator.TypeDescription)); //existingVmIndicator.InitialValueField = indicator.Value; } } //also load other data (nr decimals etc) ExecuteTaxCalculation(null); } } else { var selectedIndicatorList = indicatorRepository.Get(setupModel.SelectedIndicatorList.Id); var dbIndicators = VmUtils.Deserialize<List<TaxIndicator>>(selectedIndicatorList.Content); var vmList = dbIndicators.ToVmList(); vmList.ForEach(p => { if (p.Type == TaxIndicatorType.Numeric) { p.ValueField = "0"; } }); //if a load was performed, load all the data if (setupModel.CompletedTaxIndicatorId != 0) { var completed = taxCalculationRepository.Get(setupModel.CompletedTaxIndicatorId); savedTaxCalculation = completed; TaxCalculationOtherData otherData = VmUtils.Deserialize<TaxCalculationOtherData>(completed.OtherData); savedChosenName = otherData.Name; var completeIndicatorDbModel = VmUtils.Deserialize<CompletedIndicatorDbModel>(completed.Content); vmList.ForEach(p => { if (p.NrCrt.HasValue) { var existing = completeIndicatorDbModel.CompletedIndicators.First(i => i.NrCrt == p.NrCrt.Value.ToString()); if (existing != null) { //existing.Value = existing.Value.Replace(",", string.Empty); existing.Value = existing.Value.Replace(".", string.Empty); p.ValueField = existing.Value; } } }); } TaxIndicators = new ObservableCollection<TaxIndicatorViewModel>(vmList); ExecuteTaxCalculation(null); } } catch (Exception ex) { Logger.Instance.Log.Error(ex); WindowHelper.OpenErrorDialog(Messages.Error_LoadingData); } }
/// <summary> /// Create a new TaxCalculations object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="indicatorId">Initial value of the IndicatorId property.</param> /// <param name="rectifying">Initial value of the Rectifying property.</param> /// <param name="companyId">Initial value of the CompanyId property.</param> public static TaxCalculations CreateTaxCalculations(global::System.Int64 id, global::System.Int64 indicatorId, global::System.Boolean rectifying, global::System.Int64 companyId) { TaxCalculations taxCalculations = new TaxCalculations(); taxCalculations.Id = id; taxCalculations.IndicatorId = indicatorId; taxCalculations.Rectifying = rectifying; taxCalculations.CompanyId = companyId; return taxCalculations; }
/// <summary> /// Deprecated Method for adding a new object to the TaxCalculations EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToTaxCalculations(TaxCalculations taxCalculations) { base.AddObject("TaxCalculations", taxCalculations); }