public SpendModule(ISpendService spendService) { Get["/spend"] = _ => { var spendIdea = spendService.GetRandomIdea(); return(Response.AsJson(spendIdea)); }; }
private SummaryModel GetSummaryModelForTransactions(IEnumerable <DailyTransactionBlockViewModel> transactions) { var totalSpent = transactions.Sum(x => x.TotalSpent); var totalReceived = transactions.Sum(x => x.TotalReceived); var avgDailySpend = Math.Round(transactions.Average(x => x.TotalSpent), 0); var capital = totalReceived - totalSpent; var capitalBeforeSpend = capital; var spendingSuggestions = new List <SpendModel>(); while (capital > 0) { var spendIdea = _spendService.GetRandomIdea(); spendingSuggestions.Add(spendIdea); capital = capital - spendIdea.Price; } var summary = new SummaryModel { TotalSpent = totalSpent, TotalReceived = totalReceived, AverageDailySpend = avgDailySpend, Capital = capitalBeforeSpend, SpendingSuggestions = spendingSuggestions }; var assets = _assetService.GetAll(); summary.TotalAssetWorth = assets.Sum(a => a.Worth); return(summary); }