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 EventRest(Event source) { Id = source.Id; Name = source.Name; Description = source.Description; StartDate = JsonDate.ToString(source.StartDate); Bros = source.Bros.Select(b => b.Id).ToList(); }
public TransactionRest(Transaction transaction) { Id = transaction.Id; Date = JsonDate.ToString(transaction.Date); Amount = transaction.Amount; Rate = transaction.Rate.ToString(CultureInfo.InvariantCulture); Currency = transaction.Currency.Id; Source = transaction.Source.Id; Targets = transaction.Targets.Select(t => t.Id).ToList(); Event = transaction.Event != null ? transaction.Event.Id : (int?)null; Comment = transaction.Comment; }
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); }
public ExchangeRateRest(ExchangeRate rate) { Currency = rate.Currency.Id; Date = JsonDate.ToString(rate.Date); Rate = rate.Rate; }