Beispiel #1
0
 public void AddDeposit(Deposit deposit)
 {
     using (var context = new DepositDataContext(_connectionString))
     {
         context.Deposits.InsertOnSubmit(deposit);
         context.SubmitChanges();
     }
 }
Beispiel #2
0
        public IEnumerable <Deposit> GetDepositsById(int contribId)
        {
            List <Deposit> deposits = new List <Deposit>();

            using (var context = new DepositDataContext(_connectionString))
            {
                deposits = context.Deposits.Where(d => d.ContributorId == contribId).ToList();
            }
            return(deposits);
        }
Beispiel #3
0
        public decimal GetContributorBalance(int contributorId)
        {
            decimal contributions = 0;
            decimal deposits      = 0;

            using (var context = new DepositDataContext(_connectionString))
            {
                deposits = context.Deposits.Where(d => d.ContributorId == contributorId).Select(d => d.Amount).Sum();
            }
            using (var context = new ContributionDataContext(_connectionString))
            {
                contributions = context.Contributions.Any(c => c.ContributorId == contributorId) ? context.Contributions.Where(c => c.ContributorId == contributorId).Select(c => c.Amount).Sum() : 0;
            }
            return(deposits - contributions);
        }
Beispiel #4
0
        public decimal GetTotal()
        {
            //can make code prettier by using GetContributorBalance
            //but that's two database hits per contributor - this is two hits total
            decimal contributions = 0;
            decimal deposits      = 0;

            using (var context = new ContributionDataContext(_connectionString))
            {
                contributions = context.Contributions.Any() ? context.Contributions.Select(c => c.Amount).Sum() : 0;
            }
            using (var context = new DepositDataContext(_connectionString))
            {
                deposits = context.Deposits.Select(d => d.Amount).Sum();
            }
            return(deposits - contributions);
        }