public decimal GetTotalExpenceAmount(int year) { decimal sum = 0; foreach (var ex in Expences.Where(x => x.Date.Year == year)) { sum += ex.Amount; } return(sum); }
public decimal GetBalanceForDate(DateTime date) { var lastBalanceBeforeDate = Balances.Where(x => x.Date <= date).OrderByDescending(x => x.Date).FirstOrDefault(); if (lastBalanceBeforeDate != null) { var sumExpences = Expences.Where(x => x.Date > lastBalanceBeforeDate.Date && x.Date <= date).Sum(x => x.Amount); var sumIncome = Income.Where(x => x.Date > lastBalanceBeforeDate.Date && x.Date <= date).Sum(x => x.Amount); var sum = sumIncome - sumExpences; return(lastBalanceBeforeDate.Amount + sum); } else { var sumExpences = Expences.Where(x => x.Date <= date).Sum(x => x.Amount); var sumIncome = Income.Where(x => x.Date <= date).Sum(x => x.Amount); return(sumIncome - sumExpences); } }