public ActionResult Create(TransactionRest transaction)
        {
            using (var db = DbFactory.Open())
            {
                var dlTransaction = TransactionFromRest(transaction, db);
                db.Session.Save(dlTransaction);
                db.Session.Save(NotificationCreator.ForCreatedTransaction(dlTransaction));
                db.Commit();

                var response = new TransactionRest(dlTransaction);
                Logger.I("Created transaction {0}", response.ToJson());
                return Json(response);
            }
        }
        private Transaction TransactionFromRest(TransactionRest source, Db db, Transaction target = null)
        {
            target = target ?? new Transaction();
            if (source.Id.HasValue)
            {
                target.Id = source.Id.Value;
            }
            target.Date = JsonDate.Parse(source.Date);
            target.Amount = source.Amount;
            target.Rate = decimal.Parse(source.Rate, CultureInfo.InvariantCulture);
            target.Comment = source.Comment ?? "";

            target.Source = source.Source.Load<Bro>(db);
            target.Targets = source.Targets.Load<Bro>(db).ToArray();
            if (source.Event.HasValue)
            {
                target.Event = source.Event.Value.Load<Event>(db);
            }
            else
            {
                target.Event = null;
            }
            target.Currency = source.Currency.Load<Currency>(db);

            return target;
        }
        public ActionResult Update(TransactionRest transaction)
        {
            if (!transaction.Id.HasValue)
            {
                Logger.I("Attempt to update transaction without id");
                Response.StatusCode = 400;
                return Json(new { Field = "Id", Message = "Missing Id" });
            }

            using (var db = DbFactory.Open())
            {
                var oldTransaction = db.Load<Transaction>(transaction.Id.Value);
                var newTransaction = TransactionFromRest(transaction, db);
                db.Session.Save(NotificationCreator.ForUpdatedTransaction(oldTransaction, newTransaction));

                db.Session.Update(TransactionFromRest(transaction, db, oldTransaction));
                db.Commit();

                var response = new TransactionRest(newTransaction);
                Logger.I("Updated transaction {0}", response.ToJson());
                return Json(response);
            }
        }