public ActionResult CreateDeposit(TransactionsVM model)
        {
            if (ModelState.IsValid)
            {
                var transaction = new Transaction()
                {
                    AccountId       = model.BankAccountId,
                    BudgetItemId    = model.BudgetItemId,
                    OwnerId         = User.Identity.GetUserId(),
                    TransactionType = model.TransactionType,
                    Created         = DateTime.Now,
                    Amount          = model.Amount,
                    Memo            = model.Memo,
                    IsDeleted       = false
                };

                db.Transactions.Add(transaction);
                db.SaveChanges();

                var thisTransaction = db.Transactions.Include(t => t.BudgetItem).FirstOrDefault(t => t.Id == transaction.Id);
                thisTransaction.UpdateBalances();

                return(RedirectToAction("Dashboard", "Home"));
            }

            ViewBag.ErrorMessage = "Something went wrong.  Please try again.";
            ViewBag.AccountId    = new SelectList(db.BankAccounts, "Id", "AccountName");
            ViewBag.BudgetItemId = new SelectList(db.BudgetItems, "Id", "ItemName");

            var tryAgain = new TransactionsVM();

            tryAgain.TransactionType = TransactionType.Deposit;

            return(View(tryAgain));
        }
Beispiel #2
0
 public async Task <IActionResult> Transactions(int id, [Bind("Start, End")] TransactionsVM tlvm)
 {
     if (ModelState.IsValid)
     {
         if (tlvm.Start <= DateTime.UnixEpoch)
         {
             tlvm.Start = DateTime.Today;
         }
         if (tlvm.End < tlvm.Start)
         {
             tlvm.End = tlvm.Start.AddDays(1).AddTicks(-1);
         }
         var trans = (await _repo.GetTransactions())
                     .Where(trans => (trans.AccountID == id))
                     .Where(trans => trans.TransTime >= tlvm.Start)
                     .Where(trans => trans.TransTime <= tlvm.End.AddDays(1).AddTicks(-1))
                     .ToList();
         List <Transaction> validTrans = new List <Transaction>();
         foreach (var item in trans)
         {
             validTrans.Add(item);
         }
         foreach (var item in validTrans)
         {
             tlvm.Transactions.Add(item);
         }
     }
     return(View(tlvm));
 }
        // GET: Transactions/CreateDeposit
        public ActionResult CreateDeposit()
        {
            ViewBag.BankAccountId = new SelectList(db.BankAccounts, "Id", "AccountName");
            ViewBag.BudgetItemId  = new SelectList(db.BudgetItems, "Id", "ItemName");

            var model = new TransactionsVM();

            model.TransactionType = TransactionType.Deposit;
            return(View(model));
        }
 public TransactionsPage()
 {
     InitializeComponent();
     BindingContext = model = new TransactionsVM();
 }