public FinancialListVm GetViewModel(Guid?Id) { var vm = new FinancialListVm() { AllRows = _rep.GetAll().Select(x => new FinancialItemlVm() { Id = x.Id, Amount = x.Amount, Description = x.Description, InScore = new BootstrapSelectVm() { SourceList = _scoreList, SelectedItem = (x.InScore == null) ? null : x.InScore.Id.ToString(), SelectedItemText = (x.InScore == null) ? null : x.InScore.Name }, OutScore = new BootstrapSelectVm() { SourceList = _scoreList, SelectedItem = (x.OutScore == null) ? null : x.OutScore.Id.ToString(), SelectedItemText = (x.OutScore == null) ? null : x.OutScore.Name }, TransactionCategory = new BootstrapSelectVm() { SourceList = _catList, SelectedItem = (x.TransactionCategory == null) ? null : x.TransactionCategory.Id.ToString(), SelectedItemText = (x.TransactionCategory == null) ? null : x.TransactionCategory.Name }, TransactionDate = x.TransactionDate, TransactionType = new BootstrapSelectVm() { SourceList = TransactionTypes.Incoming.ToList(), SelectedItem = x.TransactionType.ToString(), SelectedItemText = x.TransactionType.GetDescriptionOfEnum() } }) }; if ((Id == null) || (Id == Guid.Empty)) { vm.NewItem = new FinancialItemlVm() { TransactionDate = DateTime.Now, InScore = new BootstrapSelectVm() { SourceList = _scoreList }, OutScore = new BootstrapSelectVm() { SourceList = _scoreList }, TransactionCategory = new BootstrapSelectVm() { SourceList = _catList }, TransactionType = new BootstrapSelectVm() { SourceList = TransactionTypes.Incoming.ToList() } }; } else { vm.NewItem = GetById((Guid)Id); } return(vm); }
public ActionResult AddOrUpdateFinancial(FinancialListVm vm) { _financProvider.AddOrUpdateTransaction(vm.NewItem); vm = new FinancialListVm(); return(RedirectToAction("FinancialView")); }