public void DeleteTransaction(Transaction transaction) { TransactionCommandFactory.CreateCommand(transaction).Undo(); uow.TransactionRepository.Delete(transaction); uow.Save(); }
public ActionResult Create(Transaction transaction) { if (ModelState.IsValid) { Services.TransactionService.InsertTransaction(transaction, User.Identity.Name); return RedirectToAction("Index"); } PopulateDropDownLists(transaction); return View(transaction); }
private void PopulateDropDownLists(Transaction transaction = null) { int envelopeID = (transaction != null) ? transaction.EnvelopeID : 0; TransactionType transactionType = (transaction != null) ? transaction.Type : TransactionType.Expense; PopulateEnvelopeDropDownList(envelopeID); PopulateTransactionTypeDropDownList(transactionType); }
public static ITransactionCommand CreateCommand(Transaction transaction) { switch (transaction.Type) { case TransactionType.Expense: return new ExpenseCommand(transaction); case TransactionType.Deposit: return new DepositCommand(transaction); default: throw new ArgumentException("Invalid transaction type of " + transaction.Type); } }
public ExpenseCommand(Transaction transaction) { this.transaction = transaction; }
public DepositCommand(Transaction transaction) { this.transaction = transaction; }
public JsonResult Edit(string username, Transaction t) { Services.TransactionService.UpdateTransaction(t, username); return Json(new { success = true, data = new { t.TransactionID, t.Type, t.EnvelopeID, t.Amount, t.TransactionDate, t.UserName, t.Payee, t.Notes } }); }
public void InsertTransaction(Transaction transaction, string username) { // Use the absolute value of the transaction amount. // If user enters -$10.00 for an expense, then we will assume // that the user meant to deduct $10.00 from the envelope. transaction.Amount = Math.Abs(transaction.Amount); // Assign values that are not provided by the user transaction.UserName = username; transaction.CreatedDate = DateTime.Now; transaction.Envelope = uow.EnvelopeRepository.GetByPK(transaction.EnvelopeID); TransactionCommandFactory.CreateCommand(transaction).Execute(); uow.TransactionRepository.Insert(transaction); uow.Save(); }
public void UpdateTransaction(Transaction transaction, string username) { Transaction transactionBeforeUpdate = uow.TransactionRepository.GetByPK(transaction.TransactionID); transaction.Amount = Math.Abs(transaction.Amount); // The transaction object passed to this method // is not the same transaction object before it was modified, // so we need to copy values over from the original object transaction.Envelope = uow.EnvelopeRepository.GetByPK(transaction.EnvelopeID); transaction.CreatedDate = transactionBeforeUpdate.CreatedDate; transaction.UserName = username; // Undo what the transaction did before it was modified TransactionCommandFactory.CreateCommand(transactionBeforeUpdate).Undo(); // Re-run the transaction with the new changes TransactionCommandFactory.CreateCommand(transaction).Execute(); uow.TransactionRepository.Detach(transactionBeforeUpdate); uow.TransactionRepository.Update(transaction); uow.Save(); }