public ActionResult New(TransactionViewModel newTransaction)
        {
            if (!ModelState.IsValid)
            {
                return View(newTransaction);
            }

            //ToDo: add Automapper here
            var transaction = new Transaction {
                Amount = newTransaction.Amount,
                CompletedOn = newTransaction.CompletedOn,
                DealResult = newTransaction.DealResult,
                ExchangeRate = newTransaction.ExchangeRate,
                Username = User.Identity.Name,
                Description = newTransaction.Description
            };

            var result = _transactionService.AddTransaction(transaction);

            if (result.IsSuccess)
            {
                return RedirectToAction("Index", "Transaction");
            }

            //if we are here than we've got an error(s)
            ModelState.AddModelError("", result.MessageList.FirstOrDefault());

            return View(newTransaction);

        }
예제 #2
0
        public OperationResult AddTransaction(Transaction newTransaction)
        {
            var op = new OperationResult();

            try
            {
                _repository.AddTransaction(newTransaction);
            }
            catch(Exception ex)
            {
                Debug.Write(string.Format("Error during attempt to add new transaction: {0}", ex));
                op.IsSuccess = false;
                op.AddMessage("Can't add new transaction. Please try again or contact support.");
            }

            return op;
        }
        public void AddTransaction(Transaction newTransaction)
        {
            _dbContext.Transactions.Add(newTransaction);

            _dbContext.SaveChanges();
        }