Beispiel #1
0
        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 GetRates(string date)
        {
            var d = JsonDate.Parse(date);

            using (var db = DbFactory.Open())
            {
                var ratesQuerable = db.Query <ExchangeRate>();
                var rates         = db.Query <Currency>().ToList()
                                    .Select(c => ExchangeRateProvider.Get(ratesQuerable, c.Id, d))
                                    .Select(r => new ExchangeRateRest(r))
                                    .ToList();
                return(Json(rates, JsonRequestBehavior.AllowGet));
            }
        }
        private Event EventFromRest(EventRest source, Db db)
        {
            var target = new Event();

            if (source.Id.HasValue)
            {
                target.Id = source.Id.Value;
            }
            target.Name        = source.Name;
            target.StartDate   = JsonDate.Parse(source.StartDate);
            target.Description = source.Description ?? "";
            target.Bros.AddRange(source.Bros.Load <Bro>(db));
            return(target);
        }