public FinancialItemlVm GetById(Guid Id) { var entity = _rep.GetById(Id); var item = new FinancialItemlVm() { Id = entity.Id, Amount = entity.Amount, Description = entity.Description, InScore = new BootstrapSelectVm() { SourceList = _scoreList, SelectedItem = (entity.InScore == null) ? null : entity.InScore.Id.ToString(), SelectedItemText = (entity.InScore == null) ? null : entity.InScore.Name }, OutScore = new BootstrapSelectVm() { SourceList = _scoreList, SelectedItem = (entity.OutScore == null) ? null : entity.OutScore.Id.ToString(), SelectedItemText = (entity.OutScore == null) ? null : entity.OutScore.Name }, TransactionCategory = new BootstrapSelectVm() { SourceList = _catList, SelectedItem = (entity.TransactionCategory == null) ? null : entity.TransactionCategory.Id.ToString(), SelectedItemText = (entity.TransactionCategory == null) ? null : entity.TransactionCategory.Name }, TransactionDate = entity.TransactionDate, TransactionType = new BootstrapSelectVm() { SourceList = TransactionTypes.Incoming.ToList(), SelectedItem = entity.TransactionType.ToString(), SelectedItemText = entity.TransactionType.GetDescriptionOfEnum() } }; return(item); }
public void AddOrUpdateTransaction(FinancialItemlVm vm) { Transaction entity = vm.Id == Guid.Empty ? new Transaction() { Id = Guid.NewGuid() } : _rep.GetById(vm.Id); double lastAmount = entity.Amount; entity.Amount = vm.Amount; entity.Description = vm.Description; entity.InScore = vm.InScore.SelectedItem == null ? null : _scRep.GetById(Guid.Parse(vm.InScore.SelectedItem)); entity.OutScore = vm.OutScore.SelectedItem == null ? null : _scRep.GetById(Guid.Parse(vm.OutScore.SelectedItem)); entity.TransactionDate = vm.TransactionDate; entity.TransactionCategory = vm.TransactionCategory.SelectedItem == null ? null : _catRep.GetById(Guid.Parse(vm.TransactionCategory.SelectedItem)); if (vm.TransactionType.SelectedItem == "Incoming") { entity.TransactionType = TransactionTypes.Incoming; entity.InScore.Balance -= lastAmount; entity.InScore.Balance += vm.Amount; } if (vm.TransactionType.SelectedItem == "Outcoming") { entity.TransactionType = TransactionTypes.Outcoming; entity.OutScore.Balance += lastAmount; entity.OutScore.Balance -= vm.Amount; } if (vm.TransactionType.SelectedItem == "Transfer") { entity.TransactionType = TransactionTypes.Transfer; entity.OutScore.Balance += lastAmount; entity.InScore.Balance -= lastAmount; entity.OutScore.Balance -= vm.Amount; entity.InScore.Balance += vm.Amount; } if (vm.Id == Guid.Empty) { _rep.Insert(entity); } else { _rep.Update(entity); } _rep.Save(); }