My repository returns a list of Accounts.
Each account has a date and a MoneySpent decimal amount. So, I have my list of Accounts and in my controller I'm trying to process this list a little.
I want to have an object which contains the string name of all the months in my Account list and a Sum of all money spent for that month.
Here is what I have 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 monthlyTotals?
Also, I've been using strongly typed views with ViewModels for each view, so what type should I make monthlyTotals so I can add it as a field on my ViewModel and pass it to my View?