public void SaveTransaction(TransactionDto dto)
 {
     using (var conn = new SqlConnection(_connectionString))
     {
         conn.Open();
         var query = string.Format(@"
     if exists(select null from Transactions where id = {0})
     begin
     update transactions
     set Account = '{1}',description = '{2}', currencyCode = '{3}', amount = '{4}'
     where id = {0}
     end
     ", dto.Id);
         using (var cmd = new SqlCommand(query, conn))
         {
             cmd.ExecuteNonQuery();
         }
     }
 }
        public ActionResult SaveTransaction(TransactionModel transaction)
        {
            if (transaction == null) ModelState.AddModelError("ValidationError", "Invalid Transaction data");
            if (!ModelState.IsValid) return View("View", transaction);

            var dto = new TransactionDto(transaction.Id,transaction.Account, transaction.Description, transaction.CurrencyCode,
                                         transaction.Amount);
            if (!ModelState.IsValid) return View("View", transaction);

            var tran = new Transaction(dto);
            if (!tran.IsValid()) ModelState.AddModelError("ValidationError","Invalid Transaction data");

            _transactionsService.SaveTransaction(tran);
            ViewBag.SuccessMessage = "Transaction saved successfully";
            return View("View", transaction);
        }
 public Transaction(TransactionDto dto)
 {
     _dto = dto;
 }