Пример #1
0
        public void RemoveAccount(DalAccount account)
        {
            if (ReferenceEquals(account, null))
            {
                throw new ArgumentNullException(nameof(account));
            }
            using (var context = new AccountContext())
            {
                var acc = context.Accounts.Include(accHelper => accHelper.AccountOwner)
                          .FirstOrDefault(accHelper => accHelper.AccountId == account.Id);

                var accOwner = acc.AccountOwner;

                context.Accounts.Remove(acc);
                context.AccountOwners.Remove(accOwner);
            }
        }
Пример #2
0
        public void AddAccount(DalAccount account)
        {
            if (ReferenceEquals(account, null))
            {
                throw new ArgumentNullException(nameof(account));
            }

            using (var context = new AccountContext())
            {
                var accountOwner = GetAccountOwner(account);
                context.AccountOwners.Add(accountOwner);
                context.SaveChanges();

                var accountAdd = GetAccount(account, accountOwner);
                context.Accounts.Add(accountAdd);
                context.SaveChanges();
            }
        }
Пример #3
0
        public void UpdateAccount(DalAccount account)
        {
            if (ReferenceEquals(account, null))
            {
                throw new ArgumentNullException(nameof(account));
            }

            using (var context = new AccountContext())
            {
                var acc = context.Accounts.Include(accHelper => accHelper.AccountOwner)
                          .Include(accHelper => accHelper.AccountType)
                          .FirstOrDefault(acchelper => acchelper.AccountId == account.Id);

                if (!ReferenceEquals(acc, null))
                {
                    acc.Amount = account.Amount;
                    acc.Points = account.Points;
                }
                context.SaveChanges();
            }
        }