示例#1
0
文件: Budget.cs 项目: 3normt/Budget
        public decimal GetTotalExpenceAmount(int year)
        {
            decimal sum = 0;

            foreach (var ex in Expences.Where(x => x.Date.Year == year))
            {
                sum += ex.Amount;
            }

            return(sum);
        }
示例#2
0
文件: Budget.cs 项目: 3normt/Budget
        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);
            }
        }