My repository returns a list of accounts.
Each account has a date and a decimal amount of MoneySpent. So, I have a list of accounts, and in my controller I am trying a little to process this list.
I want to have an object that contains the row name of all months in my list of accounts and the sum of all the money spent for that month.
Here is what I tried:
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Detail(int id)
{
var recentAccounts = accountRepository.GetAccountsSince(DateTime.Now.AddMonths(-6));
var monthlyTotals = from a in recentAccounts
group a by a.DateAssigned.Month.ToString("MMM") into m
select new
{
Month = m.Key,
MonthSum = m.Sum(a => a.MoneySpent)
};
return View();
}
Does this seem like the right way to calculate monthly coupons?
In addition, I use strongly typed views with ViewModels for each view, so what type should I make monthTotals, so I can add it as a field on my ViewModel and pass it to my view?