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); }
public ActionResult New() { var model = new TransactionViewModel(); model.CurrencyFrom = _currencyService.GetAllCurrencies().Select( c => new SelectListItem { Text = c.CurrencyName, Value = c.Id.ToString() }).ToList(); return View(model); }
public ActionResult Edit(TransactionViewModel model) { if (!ModelState.IsValid) { return View(model); } var transaction = _transactionService.GetTransactionById(model.Id); if (transaction == null) throw new NullReferenceException("Transaction not found."); //ToDo: rewrite transaction.Amount = model.Amount; transaction.CompletedOn = model.CompletedOn; transaction.DealResult = model.DealResult; transaction.Description = model.Description; transaction.ExchangeRate = model.ExchangeRate; transaction.Username = User.Identity.Name; var result = _transactionService.SaveChanges(); if (result.IsSuccess) { return RedirectToAction("Index"); } ModelState.AddModelError("", result.MessageList.FirstOrDefault()); return View(model); }