// TODO Subtransaction option, when if added another transaction under current would split the sum and place the values in correct accounts // EXAMPLE When spent 25 on groceries, but 5 of that was for sweets, then subtransaction would take those 5 out of total and add to sweets automatically. public async Task <ActionResult> Add(CreateTransactionVM model) { try { //Map and save transaction var transaction = model.Transaction; transaction.Date = DateTime.Now; var mappedTransaction = _mapper.Map <Transaction>(transaction); var success = await _transactionRepo.Create(mappedTransaction); if (!success) { throw new Exception("Failed to create transaction"); } //Get and update account values var accountDebited = await _accountRepo.FindById(transaction.DebitId); var accountCredited = await _accountRepo.FindById(transaction.CreditId); var success2 = await UpdateAccounts(accountDebited, accountCredited, transaction.Value); return(RedirectToAction(nameof(Index))); } catch { return(RedirectToAction(nameof(Index))); } }
public async Task <IViewComponentResult> InvokeAsync() { var accounts = await _accountRepo.FindAll(); var mappedAccounts = _mapper.Map <List <AccountVM> >(accounts); var model = new CreateTransactionVM { Accounts = mappedAccounts }; return(View(model)); }