我不完全確定如何命名標題,所以我希望我能夠關閉它。我的代碼在下面,而且所有東西都按照它應該的方式打印出來。我遇到的問題是,任何有0或更少的未付餘額的行都不需要打印。然而,這個數學是在不同的範圍內完成的(我相信),所以我不能說'哦,順便也沒有打印出未支付的餘額,如果它是零或更少。 如何創建一個while/if/foreach語句,當未付餘額小於或等於零時,這些語句只會將行打印到我的csv文件中?MVC C#使用0個餘額過濾器創建CSV文件
public IEnumerable<RowViewModel> GetUnpaidRR(int year, type[] types)
{
foreach (var type in types) type.Fees = type.Fees.ToList();
var transactions = _db.Transactions.Where(i => i.Id.Equals(Status.Success.Id));
return _db.Locations
.Include(i => i.Counts)
.Where(i => i.Owner.Report.Completed != null && i.Owner.Report.Id == year && i.Owner.primary == null)
.Select(location => new
{
Id = location.Owner.Report.Id,
Year = location.Owner.Report.year.Name,
Counts = location.Counts.Select(i => new
{
i.Id,
i.Count,
}),
FirstName = location.Owner.FirstName,
LastName = location.Owner.LastName,
paid = transactions.Where(t => t.Id == location.Owner.Report.Id).Select(n => new { n.Amount }).ToList(),
})
.AsEnumerable() // This takes all the transactions that match the selected customer ID
.Select(i => new RowViewModel(types)
{
Id = i.Id.HasValue ? i.Id.Value.ToIdString() : String.Empty,
Year = i.Year,
FirstName = i.FirstName,
LastName = i.LastName,
UnpaidBalance = types.Sum(j => i.Counts.Where(k => k.Id == j.Id).Sum(k => k.Count * j.Fees.Where(p => p.Id == year).Select(p => p.Cost).SingleOrDefault())) - i.paid.Sum(j => j.Amount),// this does all the math, takes the amount charged, subtracts the amount paid and produces the balance. If this is zero or less, I don't want the row to be printed.
});
}
快速的問題:你不能只是在你最後一個'選擇'後添加另一個'Where'? –
是的......是的,我可以......謝謝你,現在我覺得啞巴哈哈。 – BlowFish